<!DOCTYPE html>
<html class="writer-html5" lang="en" data-content_root="../../../../">
<head>
  <meta charset="utf-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>h2o_dashboard.pages.okx_dashbaord_page.okx_antbot_okx_premium_indicator_handler &mdash; AntBot 0.0.1 documentation</title>
      <link rel="stylesheet" type="text/css" href="../../../../_static/pygments.css?v=80d5e7a1" />
      <link rel="stylesheet" type="text/css" href="../../../../_static/css/theme.css?v=19f00094" />
      <link rel="stylesheet" type="text/css" href="../../../../_static/graphviz.css?v=eafc0fe6" />

  
  <!--[if lt IE 9]>
    <script src="../../../../_static/js/html5shiv.min.js"></script>
  <![endif]-->
  
        <script src="../../../../_static/jquery.js?v=5d32c60e"></script>
        <script src="../../../../_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script>
        <script src="../../../../_static/documentation_options.js?v=d45e8c67"></script>
        <script src="../../../../_static/doctools.js?v=888ff710"></script>
        <script src="../../../../_static/sphinx_highlight.js?v=dc90522c"></script>
    <script src="../../../../_static/js/theme.js"></script>
    <link rel="index" title="Index" href="../../../../genindex.html" />
    <link rel="search" title="Search" href="../../../../search.html" /> 
</head>

<body class="wy-body-for-nav"> 
  <div class="wy-grid-for-nav">
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search" >

          
          
          <a href="../../../../index.html" class="icon icon-home">
            AntBot
          </a>
              <div class="version">
                0.0.1
              </div>
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../../../../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" aria-label="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>
        </div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu">
              <p class="caption" role="heading"><span class="caption-text">Contents:</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../../../autodocumentation_python.html">autodocumentation_python</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../firebase_tools.BaseClasses.html">firebase_tools.BaseClasses</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../firebase_tools.FirestoreClient.html">firebase_tools.FirestoreClient</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../firebase_tools.authenticate.html">firebase_tools.authenticate</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../h2o_dashboard.dashboard.html">h2o_dashboard.dashboard</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../h2o_dashboard.pages.documentation_page.html">h2o_dashboard.pages.documentation_page</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../h2o_dashboard.pages.okx_dashbaord_page.okx_antbot_okx_premium_indicator_handler.html">h2o_dashboard.pages.okx_dashbaord_page.okx_antbot_okx_premium_indicator_handler</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../h2o_dashboard.pages.okx_dashbaord_page.okx_dashboard_page.html">h2o_dashboard.pages.okx_dashbaord_page.okx_dashboard_page</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../h2o_dashboard.pages.okx_streams.html">h2o_dashboard.pages.okx_streams</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../h2o_dashboard.pages.overview_page.html">h2o_dashboard.pages.overview_page</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../h2o_dashboard.util.html">h2o_dashboard.util</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../h2o_dashboard.wave_auth.html">h2o_dashboard.wave_auth</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../pyokx.Futures_Exchange_Client.html">pyokx.Futures_Exchange_Client</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../pyokx.InstrumentSearcher.html">pyokx.InstrumentSearcher</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../pyokx.data_structures.html">pyokx.data_structures</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../pyokx.low_rest_api.Account.html">pyokx.low_rest_api.Account</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../pyokx.low_rest_api.BlockTrading.html">pyokx.low_rest_api.BlockTrading</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../pyokx.low_rest_api.Convert.html">pyokx.low_rest_api.Convert</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../pyokx.low_rest_api.CopyTrading.html">pyokx.low_rest_api.CopyTrading</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../pyokx.low_rest_api.Earning.html">pyokx.low_rest_api.Earning</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../pyokx.low_rest_api.FDBroker.html">pyokx.low_rest_api.FDBroker</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../pyokx.low_rest_api.Funding.html">pyokx.low_rest_api.Funding</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../pyokx.low_rest_api.Grid.html">pyokx.low_rest_api.Grid</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../pyokx.low_rest_api.MarketData.html">pyokx.low_rest_api.MarketData</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../pyokx.low_rest_api.NDBroker.html">pyokx.low_rest_api.NDBroker</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../pyokx.low_rest_api.PublicData.html">pyokx.low_rest_api.PublicData</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../pyokx.low_rest_api.SpreadTrading.html">pyokx.low_rest_api.SpreadTrading</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../pyokx.low_rest_api.Status.html">pyokx.low_rest_api.Status</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../pyokx.low_rest_api.SubAccount.html">pyokx.low_rest_api.SubAccount</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../pyokx.low_rest_api.Trade.html">pyokx.low_rest_api.Trade</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../pyokx.low_rest_api.TradingData.html">pyokx.low_rest_api.TradingData</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../pyokx.low_rest_api.client.html">pyokx.low_rest_api.client</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../pyokx.low_rest_api.consts.html">pyokx.low_rest_api.consts</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../pyokx.low_rest_api.exceptions.html">pyokx.low_rest_api.exceptions</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../pyokx.low_rest_api.utils.html">pyokx.low_rest_api.utils</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../pyokx.okx_market_maker.market_data_service.WssMarketDataService.html">pyokx.okx_market_maker.market_data_service.WssMarketDataService</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../pyokx.okx_market_maker.market_data_service.model.Instrument.html">pyokx.okx_market_maker.market_data_service.model.Instrument</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../pyokx.okx_market_maker.market_data_service.model.MarkPx.html">pyokx.okx_market_maker.market_data_service.model.MarkPx</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../pyokx.okx_market_maker.market_data_service.model.OrderBook.html">pyokx.okx_market_maker.market_data_service.model.OrderBook</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../pyokx.okx_market_maker.market_data_service.model.Tickers.html">pyokx.okx_market_maker.market_data_service.model.Tickers</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../pyokx.okx_market_maker.order_management_service.WssOrderManagementService.html">pyokx.okx_market_maker.order_management_service.WssOrderManagementService</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../pyokx.okx_market_maker.order_management_service.model.Order.html">pyokx.okx_market_maker.order_management_service.model.Order</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../pyokx.okx_market_maker.order_management_service.model.OrderRequest.html">pyokx.okx_market_maker.order_management_service.model.OrderRequest</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../pyokx.okx_market_maker.position_management_service.WssPositionManagementService.html">pyokx.okx_market_maker.position_management_service.WssPositionManagementService</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../pyokx.okx_market_maker.position_management_service.model.Account.html">pyokx.okx_market_maker.position_management_service.model.Account</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../pyokx.okx_market_maker.position_management_service.model.BalanceAndPosition.html">pyokx.okx_market_maker.position_management_service.model.BalanceAndPosition</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../pyokx.okx_market_maker.position_management_service.model.Positions.html">pyokx.okx_market_maker.position_management_service.model.Positions</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../pyokx.okx_market_maker.run_sample_market_maker.html">pyokx.okx_market_maker.run_sample_market_maker</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../pyokx.okx_market_maker.settings.html">pyokx.okx_market_maker.settings</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../pyokx.okx_market_maker.strategy.BaseStrategy.html">pyokx.okx_market_maker.strategy.BaseStrategy</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../pyokx.okx_market_maker.strategy.SampleMM.html">pyokx.okx_market_maker.strategy.SampleMM</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../pyokx.okx_market_maker.strategy.model.StrategyMeasurement.html">pyokx.okx_market_maker.strategy.model.StrategyMeasurement</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../pyokx.okx_market_maker.strategy.model.StrategyOrder.html">pyokx.okx_market_maker.strategy.model.StrategyOrder</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../pyokx.okx_market_maker.strategy.params.ParamsLoader.html">pyokx.okx_market_maker.strategy.params.ParamsLoader</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../pyokx.okx_market_maker.strategy.risk.RiskCalculator.html">pyokx.okx_market_maker.strategy.risk.RiskCalculator</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../pyokx.okx_market_maker.strategy.risk.RiskSnapshot.html">pyokx.okx_market_maker.strategy.risk.RiskSnapshot</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../pyokx.okx_market_maker.tests.test_strategy.html">pyokx.okx_market_maker.tests.test_strategy</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../pyokx.okx_market_maker.utils.InstrumentUtil.html">pyokx.okx_market_maker.utils.InstrumentUtil</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../pyokx.okx_market_maker.utils.OkxEnum.html">pyokx.okx_market_maker.utils.OkxEnum</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../pyokx.okx_market_maker.utils.TdModeUtil.html">pyokx.okx_market_maker.utils.TdModeUtil</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../pyokx.okx_market_maker.utils.WsOrderUtil.html">pyokx.okx_market_maker.utils.WsOrderUtil</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../pyokx.redis_structured_reports.html">pyokx.redis_structured_reports</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../pyokx.redis_structured_streams.html">pyokx.redis_structured_streams</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../pyokx.rest_handling.html">pyokx.rest_handling</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../pyokx.rest_messages_service.html">pyokx.rest_messages_service</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../pyokx.strategy_handling.html">pyokx.strategy_handling</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../pyokx.test.AccountTest.html">pyokx.test.AccountTest</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../pyokx.test.BlockTradingTest.html">pyokx.test.BlockTradingTest</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../pyokx.test.BrokerTest.html">pyokx.test.BrokerTest</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../pyokx.test.ConvertTest.html">pyokx.test.ConvertTest</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../pyokx.test.CopyTradingTest.html">pyokx.test.CopyTradingTest</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../pyokx.test.EarningTest.html">pyokx.test.EarningTest</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../pyokx.test.FundingTest.html">pyokx.test.FundingTest</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../pyokx.test.GridTest.html">pyokx.test.GridTest</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../pyokx.test.MarketTest.html">pyokx.test.MarketTest</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../pyokx.test.PublicDataTest.html">pyokx.test.PublicDataTest</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../pyokx.test.SpreadTest.html">pyokx.test.SpreadTest</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../pyokx.test.StackingTest.html">pyokx.test.StackingTest</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../pyokx.test.SubAccountTest.html">pyokx.test.SubAccountTest</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../pyokx.test.TradeTest.html">pyokx.test.TradeTest</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../pyokx.test.TradingDataTest.html">pyokx.test.TradingDataTest</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../pyokx.test.WsPrivateAsyncTest.html">pyokx.test.WsPrivateAsyncTest</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../pyokx.test.WsPublicAsyncTest.html">pyokx.test.WsPublicAsyncTest</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../pyokx.websocket_handling.html">pyokx.websocket_handling</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../pyokx.ws_clients.WebSocketFactory.html">pyokx.ws_clients.WebSocketFactory</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../pyokx.ws_clients.WsPprivateAsync.html">pyokx.ws_clients.WsPprivateAsync</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../pyokx.ws_clients.WsPublicAsync.html">pyokx.ws_clients.WsPublicAsync</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../pyokx.ws_clients.WsUtils.html">pyokx.ws_clients.WsUtils</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../pyokx.ws_data_structures.html">pyokx.ws_data_structures</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../redis_tools.config.html">redis_tools.config</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../redis_tools.consumers.html">redis_tools.consumers</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../redis_tools.utils.html">redis_tools.utils</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../rest_app.html">rest_app</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../routers.api_keys.html">routers.api_keys</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../routers.login.html">routers.login</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../routers.okx.html">routers.okx</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../routers.okx_authentication.html">routers.okx_authentication</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../routers.signup.html">routers.signup</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../shared.command_execution.html">shared.command_execution</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../shared.config.html">shared.config</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../shared.configuration_parser.html">shared.configuration_parser</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../shared.data_processing_utils.html">shared.data_processing_utils</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../shared.file_directory_ops.html">shared.file_directory_ops</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../shared.logging.html">shared.logging</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../shared.string_dict_utils.html">shared.string_dict_utils</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../shared.tmp_shared.html">shared.tmp_shared</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../tradingview_tools.tradingview_widgets.html">tradingview_tools.tradingview_widgets</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../websocket_app.html">websocket_app</a></li>
</ul>

        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu" >
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../../../../index.html">AntBot</a>
      </nav>

      <div class="wy-nav-content">
        <div class="rst-content">
          <div role="navigation" aria-label="Page navigation">
  <ul class="wy-breadcrumbs">
      <li><a href="../../../../index.html" class="icon icon-home" aria-label="Home"></a></li>
          <li class="breadcrumb-item"><a href="../../../index.html">Module code</a></li>
      <li class="breadcrumb-item active">h2o_dashboard.pages.okx_dashbaord_page.okx_antbot_okx_premium_indicator_handler</li>
      <li class="wy-breadcrumbs-aside">
      </li>
  </ul>
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
             
  <h1>Source code for h2o_dashboard.pages.okx_dashbaord_page.okx_antbot_okx_premium_indicator_handler</h1><div class="highlight"><pre>
<span></span>
<span class="kn">import</span> <span class="nn">pprint</span>
<span class="kn">from</span> <span class="nn">datetime</span> <span class="kn">import</span> <span class="n">datetime</span><span class="p">,</span> <span class="n">timedelta</span>

<span class="kn">from</span> <span class="nn">h2o_wave</span> <span class="kn">import</span> <span class="n">Q</span><span class="p">,</span> <span class="n">ui</span><span class="p">,</span> <span class="n">on</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">run_on</span><span class="p">,</span> <span class="n">AsyncSite</span><span class="p">,</span> <span class="n">pack</span><span class="p">,</span> <span class="n">copy_expando</span>  <span class="c1"># noqa F401</span>
<span class="kn">from</span> <span class="nn">pydantic</span> <span class="kn">import</span> <span class="n">ValidationError</span>

<span class="kn">from</span> <span class="nn">firebase_tools.authenticate</span> <span class="kn">import</span> <span class="n">check_str_token_validity</span>
<span class="kn">from</span> <span class="nn">h2o_dashboard.util</span> <span class="kn">import</span> <span class="n">add_card</span>
<span class="kn">from</span> <span class="nn">pyokx</span> <span class="kn">import</span> <span class="n">ENFORCED_INSTRUMENT_TYPE</span>
<span class="kn">from</span> <span class="nn">pyokx.InstrumentSearcher</span> <span class="kn">import</span> <span class="n">InstrumentSearcher</span>
<span class="kn">from</span> <span class="nn">pyokx.data_structures</span> <span class="kn">import</span> <span class="n">OKXSignalInput</span><span class="p">,</span> <span class="n">InstrumentStatusReport</span><span class="p">,</span> <span class="n">PremiumIndicatorSignals</span><span class="p">,</span> \
    <span class="n">OKXPremiumIndicatorSignalRequestForm</span>
<span class="kn">from</span> <span class="nn">pyokx.redis_structured_streams</span> <span class="kn">import</span> <span class="n">get_instruments_searcher_from_redis</span>
<span class="kn">from</span> <span class="nn">pyokx.rest_handling</span> <span class="kn">import</span> <span class="n">okx_signal_handler</span><span class="p">,</span> <span class="n">validate_okx_signal_params</span><span class="p">,</span> <span class="n">okx_premium_indicator_handler</span>
<span class="kn">from</span> <span class="nn">routers.okx_authentication</span> <span class="kn">import</span> <span class="n">InstIdAPIKeyCreationRequestForm</span><span class="p">,</span> <span class="n">create_instrument_api_key</span>

<span class="n">OKX_SIGNAL_INPUT_KEYS</span> <span class="o">=</span> <span class="n">OKXSignalInput</span><span class="o">.</span><span class="n">model_fields</span><span class="o">.</span><span class="n">keys</span><span class="p">()</span>
<span class="n">OKX_PREMIUM_INDICATOR_SIGNAL_INPUT_KEYS</span> <span class="o">=</span> <span class="n">PremiumIndicatorSignals</span><span class="o">.</span><span class="n">model_fields</span><span class="o">.</span><span class="n">keys</span><span class="p">()</span>


<div class="viewcode-block" id="OKX_Premium_Indicator_Handler_Widget">
<a class="viewcode-back" href="../../../../h2o_dashboard.pages.okx_dashbaord_page.okx_antbot_okx_premium_indicator_handler.html#h2o_dashboard.pages.okx_dashbaord_page.okx_antbot_okx_premium_indicator_handler.OKX_Premium_Indicator_Handler_Widget">[docs]</a>
<span class="k">class</span> <span class="nc">OKX_Premium_Indicator_Handler_Widget</span><span class="p">:</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">q</span><span class="p">:</span> <span class="n">Q</span><span class="p">,</span> <span class="n">card_name</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">box</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">minimum_update_delay</span><span class="p">:</span> <span class="nb">int</span> <span class="o">=</span> <span class="mi">2</span> <span class="o">*</span> <span class="mi">60</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">q</span> <span class="o">=</span> <span class="n">q</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">card_name</span> <span class="o">=</span> <span class="n">card_name</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">box</span> <span class="o">=</span> <span class="n">box</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_initialized</span> <span class="o">=</span> <span class="kc">False</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">okx_futures_instruments_searcher</span><span class="p">:</span> <span class="n">InstrumentSearcher</span> <span class="o">=</span> <span class="kc">None</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">_last_update_time</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_minimum_update_delay</span> <span class="o">=</span> <span class="n">minimum_update_delay</span>

    <span class="k">async</span> <span class="k">def</span> <span class="nf">_update_stream</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="c1"># Only update every n seconds minimum, updating the instruments is not a high priority</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_last_update_time</span><span class="p">:</span>
            <span class="k">if</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_last_update_time</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">_last_update_time</span><span class="p">)</span> <span class="o">&lt;</span> <span class="n">timedelta</span><span class="p">(</span><span class="n">seconds</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_minimum_update_delay</span><span class="p">):</span>
                <span class="k">return</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_last_update_time</span> <span class="o">=</span> <span class="n">datetime</span><span class="o">.</span><span class="n">now</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">okx_futures_instruments_searcher</span> <span class="o">=</span> <span class="k">await</span> <span class="n">get_instruments_searcher_from_redis</span><span class="p">(</span>
            <span class="n">async_redis</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">q</span><span class="o">.</span><span class="n">client</span><span class="o">.</span><span class="n">async_redis</span><span class="p">,</span> <span class="n">instType</span><span class="o">=</span><span class="n">ENFORCED_INSTRUMENT_TYPE</span><span class="p">)</span>

    <span class="k">async</span> <span class="k">def</span> <span class="nf">_is_initialized</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_initialized</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">okx_futures_instruments_searcher</span>

<div class="viewcode-block" id="OKX_Premium_Indicator_Handler_Widget.add_cards">
<a class="viewcode-back" href="../../../../h2o_dashboard.pages.okx_dashbaord_page.okx_antbot_okx_premium_indicator_handler.html#h2o_dashboard.pages.okx_dashbaord_page.okx_antbot_okx_premium_indicator_handler.OKX_Premium_Indicator_Handler_Widget.add_cards">[docs]</a>
    <span class="k">async</span> <span class="k">def</span> <span class="nf">add_cards</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">_update_stream</span><span class="p">()</span>
        <span class="n">instrument_id_choices</span> <span class="o">=</span> <span class="p">[</span><span class="n">ui</span><span class="o">.</span><span class="n">choice</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="n">instID</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="n">instID</span><span class="p">)</span> <span class="k">for</span> <span class="n">instID</span> <span class="ow">in</span>
                                 <span class="bp">self</span><span class="o">.</span><span class="n">okx_futures_instruments_searcher</span><span class="o">.</span><span class="n">get_instrument_ids</span><span class="p">()]</span>
        <span class="n">bot_okx_signal_inputs</span> <span class="o">=</span> <span class="n">ui</span><span class="o">.</span><span class="n">form_card</span><span class="p">(</span>
            <span class="n">box</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">box</span><span class="p">,</span>
            <span class="n">items</span><span class="o">=</span><span class="p">[</span>
                <span class="n">ui</span><span class="o">.</span><span class="n">mini_buttons</span><span class="p">(</span><span class="n">items</span><span class="o">=</span><span class="p">[</span>
                    <span class="n">ui</span><span class="o">.</span><span class="n">mini_button</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="sa">f</span><span class="s1">&#39;okx_dashboard_page_okx_premium_indicator_validate_inputs&#39;</span><span class="p">,</span>
                                   <span class="n">label</span><span class="o">=</span><span class="s1">&#39;Validate Input&#39;</span><span class="p">,</span>
                                   <span class="n">icon</span><span class="o">=</span><span class="s1">&#39;CheckMark&#39;</span><span class="p">),</span>
                    <span class="n">ui</span><span class="o">.</span><span class="n">mini_button</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">&#39;okx_dashboard_page_okx_premium_indicator_submit_okx_signal&#39;</span><span class="p">,</span>
                                   <span class="n">label</span><span class="o">=</span><span class="s1">&#39;Submit Signal&#39;</span><span class="p">,</span>
                                   <span class="n">icon</span><span class="o">=</span><span class="s1">&#39;Send&#39;</span><span class="p">),</span>
                    <span class="n">ui</span><span class="o">.</span><span class="n">mini_button</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">&#39;okx_dashboard_page_okx_premium_indicator_generate_tv_payload&#39;</span><span class="p">,</span>
                                   <span class="n">label</span><span class="o">=</span><span class="s1">&#39;Generate TV Payload&#39;</span><span class="p">,</span>
                                   <span class="n">icon</span><span class="o">=</span><span class="s1">&#39;Send&#39;</span><span class="p">),</span>
                <span class="p">]),</span>

                <span class="n">ui</span><span class="o">.</span><span class="n">expander</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">&#39;okx_dashboard_page_okx_premium_indicator_expander&#39;</span><span class="p">,</span>
                            <span class="n">label</span><span class="o">=</span><span class="s1">&#39;OKX Premium Indicator Signal&#39;</span><span class="p">,</span> <span class="n">expanded</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
                            <span class="n">items</span><span class="o">=</span><span class="p">[</span>
                                <span class="c1"># Small note</span>
                                <span class="n">ui</span><span class="o">.</span><span class="n">message_bar</span><span class="p">(</span>
                                    <span class="nb">type</span><span class="o">=</span><span class="s1">&#39;warning&#39;</span><span class="p">,</span>
                                    <span class="n">text</span><span class="o">=</span><span class="s1">&#39;Bullish or Bearish signals will override order side&#39;</span>
                                <span class="p">),</span>
                                <span class="n">ui</span><span class="o">.</span><span class="n">message_bar</span><span class="p">(</span>
                                    <span class="nb">type</span><span class="o">=</span><span class="s1">&#39;warning&#39;</span><span class="p">,</span>
                                    <span class="n">text</span><span class="o">=</span><span class="s1">&#39;OKX SIGNAL should be validated prior to submitting&#39;</span>
                                <span class="p">),</span>
                                <span class="n">ui</span><span class="o">.</span><span class="n">mini_buttons</span><span class="p">(</span>
                                    <span class="n">items</span><span class="o">=</span><span class="p">[</span>
                                        <span class="n">ui</span><span class="o">.</span><span class="n">mini_button</span><span class="p">(</span>
                                            <span class="n">name</span><span class="o">=</span><span class="sa">f</span><span class="s1">&#39;okx_dashboard_page_okx_premium_indicator_</span><span class="si">{</span><span class="n">PremiumIndicatorSignals</span><span class="o">.</span><span class="n">Bullish</span><span class="si">}</span><span class="s1">&#39;</span><span class="p">,</span>
                                            <span class="n">label</span><span class="o">=</span><span class="s1">&#39;Bullish&#39;</span><span class="p">,</span> <span class="n">icon</span><span class="o">=</span><span class="s1">&#39;ChevronUpSmall&#39;</span><span class="p">),</span>
                                        <span class="n">ui</span><span class="o">.</span><span class="n">mini_button</span><span class="p">(</span>
                                            <span class="n">name</span><span class="o">=</span><span class="sa">f</span><span class="s1">&#39;okx_dashboard_page_okx_premium_indicator_</span><span class="si">{</span><span class="n">PremiumIndicatorSignals</span><span class="o">.</span><span class="n">Bullish_plus</span><span class="si">}</span><span class="s1">&#39;</span><span class="p">,</span>
                                            <span class="n">label</span><span class="o">=</span><span class="s1">&#39;Bullish Plus&#39;</span><span class="p">,</span> <span class="n">icon</span><span class="o">=</span><span class="s1">&#39;DoubleChevronUp8&#39;</span><span class="p">),</span>
                                        <span class="n">ui</span><span class="o">.</span><span class="n">mini_button</span><span class="p">(</span>
                                            <span class="n">name</span><span class="o">=</span><span class="sa">f</span><span class="s1">&#39;okx_dashboard_page_okx_premium_indicator_</span><span class="si">{</span><span class="n">PremiumIndicatorSignals</span><span class="o">.</span><span class="n">Bullish_Exit</span><span class="si">}</span><span class="s1">&#39;</span><span class="p">,</span>
                                            <span class="n">label</span><span class="o">=</span><span class="s1">&#39;Bullish Exit&#39;</span><span class="p">,</span> <span class="n">icon</span><span class="o">=</span><span class="s1">&#39;GroupedDescending&#39;</span><span class="p">),</span>
                                    <span class="p">]</span>
                                <span class="p">),</span>
                                <span class="n">ui</span><span class="o">.</span><span class="n">mini_buttons</span><span class="p">(</span>
                                    <span class="n">items</span><span class="o">=</span><span class="p">[</span>
                                        <span class="n">ui</span><span class="o">.</span><span class="n">mini_button</span><span class="p">(</span>
                                            <span class="n">name</span><span class="o">=</span><span class="sa">f</span><span class="s1">&#39;okx_dashboard_page_okx_premium_indicator_</span><span class="si">{</span><span class="n">PremiumIndicatorSignals</span><span class="o">.</span><span class="n">Bearish</span><span class="si">}</span><span class="s1">&#39;</span><span class="p">,</span>
                                            <span class="n">label</span><span class="o">=</span><span class="s1">&#39;Bearish&#39;</span><span class="p">,</span> <span class="n">icon</span><span class="o">=</span><span class="s1">&#39;ChevronDownSmall&#39;</span><span class="p">),</span>
                                        <span class="n">ui</span><span class="o">.</span><span class="n">mini_button</span><span class="p">(</span>
                                            <span class="n">name</span><span class="o">=</span><span class="sa">f</span><span class="s1">&#39;okx_dashboard_page_okx_premium_indicator_</span><span class="si">{</span><span class="n">PremiumIndicatorSignals</span><span class="o">.</span><span class="n">Bearish_plus</span><span class="si">}</span><span class="s1">&#39;</span><span class="p">,</span>
                                            <span class="n">label</span><span class="o">=</span><span class="s1">&#39;Bearish Plus&#39;</span><span class="p">,</span> <span class="n">icon</span><span class="o">=</span><span class="s1">&#39;DoubleChevronDown8&#39;</span><span class="p">),</span>
                                        <span class="n">ui</span><span class="o">.</span><span class="n">mini_button</span><span class="p">(</span>
                                            <span class="n">name</span><span class="o">=</span><span class="sa">f</span><span class="s1">&#39;okx_dashboard_page_okx_premium_indicator_</span><span class="si">{</span><span class="n">PremiumIndicatorSignals</span><span class="o">.</span><span class="n">Bearish_Exit</span><span class="si">}</span><span class="s1">&#39;</span><span class="p">,</span>
                                            <span class="n">label</span><span class="o">=</span><span class="s1">&#39;Bearish Exit&#39;</span><span class="p">,</span> <span class="n">icon</span><span class="o">=</span><span class="s1">&#39;GroupedAscending&#39;</span><span class="p">)</span>
                                    <span class="p">]</span>
                                <span class="p">),</span>
                                <span class="n">ui</span><span class="o">.</span><span class="n">dropdown</span><span class="p">(</span>
                                    <span class="n">name</span><span class="o">=</span><span class="sa">f</span><span class="s1">&#39;okx_dashboard_page_okx_premium_indicator_</span><span class="si">{</span><span class="n">OKXSignalInput</span><span class="o">.</span><span class="n">instID</span><span class="si">}</span><span class="s1">&#39;</span><span class="p">,</span>
                                    <span class="n">label</span><span class="o">=</span><span class="s1">&#39;Instrument ID&#39;</span><span class="p">,</span>
                                    <span class="n">choices</span><span class="o">=</span><span class="n">instrument_id_choices</span><span class="p">,</span>
                                    <span class="n">trigger</span><span class="o">=</span><span class="kc">True</span>
                                <span class="p">),</span>
                                <span class="n">ui</span><span class="o">.</span><span class="n">message_bar</span><span class="p">(</span>
                                    <span class="nb">type</span><span class="o">=</span><span class="s1">&#39;info&#39;</span><span class="p">,</span>
                                    <span class="n">text</span><span class="o">=</span><span class="s1">&#39;RECOMMENDED!&#39;</span><span class="p">,</span>
                                <span class="p">),</span>
                                <span class="n">ui</span><span class="o">.</span><span class="n">toggle</span><span class="p">(</span>
                                    <span class="n">name</span><span class="o">=</span><span class="sa">f</span><span class="s1">&#39;okx_dashboard_page_okx_premium_indicator_</span><span class="si">{</span><span class="n">OKXSignalInput</span><span class="o">.</span><span class="n">flip_position_if_opposite_side</span><span class="si">}</span><span class="s1">&#39;</span><span class="p">,</span>
                                    <span class="n">label</span><span class="o">=</span><span class="s1">&#39;Flip Position If Opposite Side&#39;</span><span class="p">,</span>
                                    <span class="n">value</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
                                    <span class="n">tooltip</span><span class="o">=</span><span class="s1">&#39;This is recommended for automated trading unless you want to keep by default &#39;</span>
                                            <span class="s1">&#39;all orders and positions untouched, unlikely unless market making&#39;</span><span class="p">),</span>

                                <span class="n">ui</span><span class="o">.</span><span class="n">expander</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">&#39;okx_dashboard_page_okx_premium_indicator_advanced_expander&#39;</span><span class="p">,</span>
                                            <span class="n">label</span><span class="o">=</span><span class="s1">&#39;Advanced&#39;</span><span class="p">,</span>
                                            <span class="n">items</span><span class="o">=</span><span class="p">[</span>
                                                <span class="n">ui</span><span class="o">.</span><span class="n">toggle</span><span class="p">(</span>
                                                    <span class="n">name</span><span class="o">=</span><span class="sa">f</span><span class="s1">&#39;okx_dashboard_page_okx_premium_indicator_</span><span class="si">{</span><span class="n">OKXSignalInput</span><span class="o">.</span><span class="n">red_button</span><span class="si">}</span><span class="s1">&#39;</span><span class="p">,</span>
                                                    <span class="n">label</span><span class="o">=</span><span class="s1">&#39;Red Button&#39;</span><span class="p">),</span>
                                                <span class="n">ui</span><span class="o">.</span><span class="n">toggle</span><span class="p">(</span>
                                                    <span class="n">name</span><span class="o">=</span><span class="sa">f</span><span class="s1">&#39;okx_dashboard_page_okx_premium_indicator_</span><span class="si">{</span><span class="n">OKXSignalInput</span><span class="o">.</span><span class="n">clear_prior_to_new_order</span><span class="si">}</span><span class="s1">&#39;</span><span class="p">,</span>
                                                    <span class="n">label</span><span class="o">=</span><span class="s1">&#39;Clear Prior To New Order&#39;</span><span class="p">),</span>
                                                <span class="n">ui</span><span class="o">.</span><span class="n">textbox</span><span class="p">(</span>
                                                    <span class="n">name</span><span class="o">=</span><span class="sa">f</span><span class="s1">&#39;okx_dashboard_page_okx_premium_indicator_</span><span class="si">{</span><span class="n">OKXSignalInput</span><span class="o">.</span><span class="n">max_orderbook_limit_price_offset</span><span class="si">}</span><span class="s1">&#39;</span><span class="p">,</span>
                                                    <span class="n">label</span><span class="o">=</span><span class="s1">&#39;Max Orderbook Limit Price Offset (USD)&#39;</span><span class="p">,</span>
                                                    <span class="n">placeholder</span><span class="o">=</span><span class="s1">&#39;float: 0.0&#39;</span><span class="p">,</span>
                                                <span class="p">),</span>
                                            <span class="p">]),</span>
                                <span class="n">ui</span><span class="o">.</span><span class="n">expander</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="sa">f</span><span class="s1">&#39;okx_dashboard_page_okx_premium_indicator_order_parameters_expander&#39;</span><span class="p">,</span>
                                            <span class="n">label</span><span class="o">=</span><span class="s1">&#39;Order Parameters&#39;</span><span class="p">,</span> <span class="n">items</span><span class="o">=</span><span class="p">[</span>
                                        <span class="n">ui</span><span class="o">.</span><span class="n">textbox</span><span class="p">(</span>
                                            <span class="n">name</span><span class="o">=</span><span class="sa">f</span><span class="s1">&#39;okx_dashboard_page_okx_premium_indicator_</span><span class="si">{</span><span class="n">OKXSignalInput</span><span class="o">.</span><span class="n">usd_order_size</span><span class="si">}</span><span class="s1">&#39;</span><span class="p">,</span>
                                            <span class="n">label</span><span class="o">=</span><span class="s1">&#39;Order Size (USD)&#39;</span><span class="p">,</span> <span class="n">placeholder</span><span class="o">=</span><span class="s1">&#39;float: 0 USD&#39;</span><span class="p">,</span>
                                        <span class="p">),</span>
                                        <span class="n">ui</span><span class="o">.</span><span class="n">textbox</span><span class="p">(</span>
                                            <span class="n">name</span><span class="o">=</span><span class="sa">f</span><span class="s1">&#39;okx_dashboard_page_okx_premium_indicator_</span><span class="si">{</span><span class="n">OKXSignalInput</span><span class="o">.</span><span class="n">leverage</span><span class="si">}</span><span class="s1">&#39;</span><span class="p">,</span>
                                            <span class="n">label</span><span class="o">=</span><span class="s1">&#39;Leverage&#39;</span><span class="p">,</span>
                                            <span class="n">placeholder</span><span class="o">=</span><span class="s1">&#39;int: 0&#39;</span><span class="p">,</span>
                                        <span class="p">),</span>
                                        <span class="n">ui</span><span class="o">.</span><span class="n">textbox</span><span class="p">(</span>
                                            <span class="n">name</span><span class="o">=</span><span class="sa">f</span><span class="s1">&#39;okx_dashboard_page_okx_premium_indicator_</span><span class="si">{</span><span class="n">OKXSignalInput</span><span class="o">.</span><span class="n">order_side</span><span class="si">}</span><span class="s1">&#39;</span><span class="p">,</span>
                                            <span class="n">label</span><span class="o">=</span><span class="s1">&#39;Order Side&#39;</span><span class="p">,</span>
                                            <span class="n">placeholder</span><span class="o">=</span><span class="s1">&#39;BUY or SELL or &quot;&quot;&#39;</span><span class="p">,</span>
                                        <span class="p">),</span>
                                        <span class="n">ui</span><span class="o">.</span><span class="n">dropdown</span><span class="p">(</span>
                                            <span class="n">name</span><span class="o">=</span><span class="sa">f</span><span class="s1">&#39;okx_dashboard_page_okx_premium_indicator_</span><span class="si">{</span><span class="n">OKXSignalInput</span><span class="o">.</span><span class="n">order_type</span><span class="si">}</span><span class="s1">&#39;</span><span class="p">,</span>
                                            <span class="n">label</span><span class="o">=</span><span class="s1">&#39;Order Type&#39;</span><span class="p">,</span>
                                            <span class="n">placeholder</span><span class="o">=</span><span class="s1">&#39;MARKET or LIMIT or POST_ONLY&#39;</span><span class="p">,</span>
                                            <span class="n">choices</span><span class="o">=</span><span class="p">[</span><span class="n">ui</span><span class="o">.</span><span class="n">choice</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">&#39;MARKET&#39;</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="s1">&#39;MARKET&#39;</span><span class="p">),</span>
                                                     <span class="n">ui</span><span class="o">.</span><span class="n">choice</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">&#39;LIMIT&#39;</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="s1">&#39;LIMIT&#39;</span><span class="p">),</span>
                                                     <span class="n">ui</span><span class="o">.</span><span class="n">choice</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">&#39;POST_ONLY&#39;</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="s1">&#39;POST_ONLY&#39;</span><span class="p">)],</span>
                                            <span class="n">value</span><span class="o">=</span><span class="s1">&#39;MARKET&#39;</span>
                                        <span class="p">),</span>
                                    <span class="p">]),</span>
                                <span class="n">ui</span><span class="o">.</span><span class="n">expander</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">&#39;okx_dashboard_page_okx_premium_indicator_tp_sl_expander&#39;</span><span class="p">,</span>
                                            <span class="n">label</span><span class="o">=</span><span class="s1">&#39;TP/SL&#39;</span><span class="p">,</span> <span class="n">items</span><span class="o">=</span><span class="p">[</span>
                                        <span class="n">ui</span><span class="o">.</span><span class="n">dropdown</span><span class="p">(</span>
                                            <span class="n">name</span><span class="o">=</span><span class="sa">f</span><span class="s1">&#39;okx_dashboard_page_okx_premium_indicator_</span><span class="si">{</span><span class="n">OKXSignalInput</span><span class="o">.</span><span class="n">tp_trigger_price_type</span><span class="si">}</span><span class="s1">&#39;</span><span class="p">,</span>
                                            <span class="n">label</span><span class="o">=</span><span class="s1">&#39;TP Trigger Price Type&#39;</span><span class="p">,</span>
                                            <span class="n">placeholder</span><span class="o">=</span><span class="s1">&#39;index or mark or last&#39;</span><span class="p">,</span>
                                            <span class="n">value</span><span class="o">=</span><span class="s1">&#39;last&#39;</span><span class="p">,</span>
                                            <span class="n">choices</span><span class="o">=</span><span class="p">[</span>
                                                <span class="c1"># &#39;index&#39;, &#39;mark&#39;, &#39;last&#39;</span>
                                                <span class="n">ui</span><span class="o">.</span><span class="n">choice</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">&#39;index&#39;</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="s1">&#39;index&#39;</span><span class="p">),</span>
                                                <span class="n">ui</span><span class="o">.</span><span class="n">choice</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">&#39;mark&#39;</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="s1">&#39;mark&#39;</span><span class="p">),</span>
                                                <span class="n">ui</span><span class="o">.</span><span class="n">choice</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">&#39;last&#39;</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="s1">&#39;last&#39;</span><span class="p">)</span>
                                            <span class="p">],</span>
                                        <span class="p">),</span>
                                        <span class="n">ui</span><span class="o">.</span><span class="n">textbox</span><span class="p">(</span>
                                            <span class="n">name</span><span class="o">=</span><span class="sa">f</span><span class="s1">&#39;okx_dashboard_page_okx_premium_indicator_</span><span class="si">{</span><span class="n">OKXSignalInput</span><span class="o">.</span><span class="n">tp_execution_price_offset</span><span class="si">}</span><span class="s1">&#39;</span><span class="p">,</span>
                                            <span class="n">label</span><span class="o">=</span><span class="s1">&#39;TP Execution Price Offset (USD)&#39;</span><span class="p">,</span>
                                            <span class="n">placeholder</span><span class="o">=</span><span class="s1">&#39;float: 0.0 USD&#39;</span><span class="p">,</span>
                                        <span class="p">),</span>
                                        <span class="n">ui</span><span class="o">.</span><span class="n">textbox</span><span class="p">(</span>
                                            <span class="n">name</span><span class="o">=</span><span class="sa">f</span><span class="s1">&#39;okx_dashboard_page_okx_premium_indicator_</span><span class="si">{</span><span class="n">OKXSignalInput</span><span class="o">.</span><span class="n">tp_trigger_price_offset</span><span class="si">}</span><span class="s1">&#39;</span><span class="p">,</span>
                                            <span class="n">label</span><span class="o">=</span><span class="s1">&#39;Take Profit Trigger Offset (USD)&#39;</span><span class="p">,</span>
                                            <span class="n">placeholder</span><span class="o">=</span><span class="s1">&#39;float: 0.0 USD&#39;</span><span class="p">,</span>
                                        <span class="p">),</span>
                                        <span class="n">ui</span><span class="o">.</span><span class="n">dropdown</span><span class="p">(</span>
                                            <span class="n">name</span><span class="o">=</span><span class="sa">f</span><span class="s1">&#39;okx_dashboard_page_okx_premium_indicator_</span><span class="si">{</span><span class="n">OKXSignalInput</span><span class="o">.</span><span class="n">sl_trigger_price_type</span><span class="si">}</span><span class="s1">&#39;</span><span class="p">,</span>
                                            <span class="n">label</span><span class="o">=</span><span class="s1">&#39;SL Trigger Price Type&#39;</span><span class="p">,</span>
                                            <span class="n">placeholder</span><span class="o">=</span><span class="s1">&#39;index or mark or last&#39;</span><span class="p">,</span>
                                            <span class="n">value</span><span class="o">=</span><span class="s1">&#39;last&#39;</span><span class="p">,</span>
                                            <span class="n">choices</span><span class="o">=</span><span class="p">[</span>
                                                <span class="c1"># &#39;index&#39;, &#39;mark&#39;, &#39;last&#39;</span>
                                                <span class="n">ui</span><span class="o">.</span><span class="n">choice</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">&#39;index&#39;</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="s1">&#39;index&#39;</span><span class="p">),</span>
                                                <span class="n">ui</span><span class="o">.</span><span class="n">choice</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">&#39;mark&#39;</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="s1">&#39;mark&#39;</span><span class="p">),</span>
                                                <span class="n">ui</span><span class="o">.</span><span class="n">choice</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">&#39;last&#39;</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="s1">&#39;last&#39;</span><span class="p">)</span>
                                            <span class="p">],</span>
                                        <span class="p">),</span>
                                        <span class="n">ui</span><span class="o">.</span><span class="n">textbox</span><span class="p">(</span>
                                            <span class="n">name</span><span class="o">=</span><span class="sa">f</span><span class="s1">&#39;okx_dashboard_page_okx_premium_indicator_</span><span class="si">{</span><span class="n">OKXSignalInput</span><span class="o">.</span><span class="n">sl_execution_price_offset</span><span class="si">}</span><span class="s1">&#39;</span><span class="p">,</span>
                                            <span class="n">label</span><span class="o">=</span><span class="s1">&#39;SL Execution Price Offset (USD)&#39;</span><span class="p">,</span>
                                            <span class="n">placeholder</span><span class="o">=</span><span class="s1">&#39;float: 0.0 USD&#39;</span><span class="p">),</span>
                                        <span class="n">ui</span><span class="o">.</span><span class="n">textbox</span><span class="p">(</span>
                                            <span class="n">name</span><span class="o">=</span><span class="sa">f</span><span class="s1">&#39;okx_dashboard_page_okx_premium_indicator_</span><span class="si">{</span><span class="n">OKXSignalInput</span><span class="o">.</span><span class="n">sl_trigger_price_offset</span><span class="si">}</span><span class="s1">&#39;</span><span class="p">,</span>
                                            <span class="n">label</span><span class="o">=</span><span class="s1">&#39;Stop Loss Trigger Offset (USD)&#39;</span><span class="p">,</span>
                                            <span class="n">placeholder</span><span class="o">=</span><span class="s1">&#39;float: 0.0 USD&#39;</span><span class="p">,</span>
                                        <span class="p">),</span>

                                    <span class="p">]),</span>
                                <span class="n">ui</span><span class="o">.</span><span class="n">expander</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">&#39;okx_dashboard_page_okx_premium_indicator_trailing_stop_expander&#39;</span><span class="p">,</span>
                                            <span class="n">label</span><span class="o">=</span><span class="s1">&#39;Trailing Stop&#39;</span><span class="p">,</span> <span class="n">items</span><span class="o">=</span><span class="p">[</span>
                                        <span class="n">ui</span><span class="o">.</span><span class="n">textbox</span><span class="p">(</span>
                                            <span class="n">name</span><span class="o">=</span><span class="sa">f</span><span class="s1">&#39;okx_dashboard_page_okx_premium_indicator_</span><span class="si">{</span><span class="n">OKXSignalInput</span><span class="o">.</span><span class="n">trailing_stop_activation_price_offset</span><span class="si">}</span><span class="s1">&#39;</span><span class="p">,</span>
                                            <span class="n">label</span><span class="o">=</span><span class="s1">&#39;Trailing Stop Activation Offset (USD)&#39;</span><span class="p">,</span>
                                            <span class="n">placeholder</span><span class="o">=</span><span class="s1">&#39;float: 0.0 (USD)&#39;</span><span class="p">),</span>
                                        <span class="n">ui</span><span class="o">.</span><span class="n">textbox</span><span class="p">(</span>
                                            <span class="n">name</span><span class="o">=</span><span class="sa">f</span><span class="s1">&#39;okx_dashboard_page_okx_premium_indicator_</span><span class="si">{</span><span class="n">OKXSignalInput</span><span class="o">.</span><span class="n">trailing_stop_callback_offset</span><span class="si">}</span><span class="s1">&#39;</span><span class="p">,</span>
                                            <span class="n">label</span><span class="o">=</span><span class="s1">&#39;Trailing Stop Callback Offset (USD)&#39;</span><span class="p">,</span>
                                            <span class="n">placeholder</span><span class="o">=</span><span class="s1">&#39;float: 0.0 (USD)&#39;</span><span class="p">),</span>
                                    <span class="p">]),</span>
                                <span class="n">ui</span><span class="o">.</span><span class="n">expander</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">&#39;okx_dashboard_page_okx_premium_indicator_dca_expander&#39;</span><span class="p">,</span>
                                            <span class="n">label</span><span class="o">=</span><span class="s1">&#39;SINGLE DCA PARAMS (UI-Form not enabled)&#39;</span><span class="p">,</span> <span class="n">items</span><span class="o">=</span><span class="p">[</span>
                                            <span class="c1"># DCAInputParameters(</span>
                                            <span class="c1">#         usd_amount=100,</span>
                                            <span class="c1">#         order_type=&quot;LIMIT&quot;,</span>
                                            <span class="c1">#         order_side=&quot;BUY&quot;,</span>
                                            <span class="c1">#         trigger_price_offset=100,</span>
                                            <span class="c1">#         execution_price_offset=90,</span>
                                            <span class="c1">#         tp_trigger_price_offset=100,</span>
                                            <span class="c1">#         tp_execution_price_offset=90,</span>
                                            <span class="c1">#         sl_trigger_price_offset=100,</span>
                                            <span class="c1">#         sl_execution_price_offset=90</span>
                                            <span class="c1">#     ),</span>
                                        <span class="n">ui</span><span class="o">.</span><span class="n">textbox</span><span class="p">(</span>
                                            <span class="n">name</span><span class="o">=</span><span class="sa">f</span><span class="s1">&#39;okx_dashboard_page_okx_premium_indicator_</span><span class="si">{</span><span class="n">OKXSignalInput</span><span class="o">.</span><span class="n">trailing_stop_callback_offset</span><span class="si">}</span><span class="s1">&#39;</span><span class="p">,</span>
                                            <span class="n">label</span><span class="o">=</span><span class="s2">&quot;&quot;&quot;DCAInputParameters(</span>
<span class="s2">                                                    usd_amount=100,</span>
<span class="s2">                                                    order_type=&quot;LIMIT&quot;,</span>
<span class="s2">                                                    order_side=&quot;BUY&quot;,</span>
<span class="s2">                                                    trigger_price_offset=100,</span>
<span class="s2">                                                    execution_price_offset=90,</span>
<span class="s2">                                                    tp_trigger_price_offset=100,</span>
<span class="s2">                                                    tp_execution_price_offset=90,</span>
<span class="s2">                                                    sl_trigger_price_offset=100,</span>
<span class="s2">                                                    sl_execution_price_offset=90</span>
<span class="s2">                                                ),&quot;&quot;&quot;</span><span class="p">,</span>
                                            <span class="c1"># placeholder=&#39;float: 0.0 (USD)&#39;</span>
                                        <span class="p">),</span>
                                    <span class="p">]),</span>
                            <span class="p">]),</span>
            <span class="p">])</span>




        <span class="n">output_value</span> <span class="o">=</span> <span class="s2">&quot;When ready or in doubt, </span><span class="se">\n</span><span class="s2">  press the `Validate Input Model` button&quot;</span> <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">q</span><span class="o">.</span><span class="n">client</span><span class="o">.</span><span class="n">okx_dashboard_page_okx_signal_input</span> <span class="k">else</span> <span class="bp">self</span><span class="o">.</span><span class="n">q</span><span class="o">.</span><span class="n">client</span><span class="o">.</span><span class="n">okx_dashboard_page_okx_signal_input</span><span class="o">.</span><span class="n">model_dump</span><span class="p">()</span>
        <span class="n">output_value</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">output_value</span><span class="p">)</span> <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">output_value</span><span class="p">,</span> <span class="nb">dict</span><span class="p">)</span> <span class="k">else</span> <span class="n">pprint</span><span class="o">.</span><span class="n">pformat</span><span class="p">(</span><span class="n">output_value</span><span class="p">,</span>
                                                                                                   <span class="n">compact</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
                                                                                                   <span class="n">sort_dicts</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
                                                                                                   <span class="n">width</span><span class="o">=</span><span class="mi">100</span><span class="p">,</span> <span class="n">depth</span><span class="o">=</span><span class="mi">5</span><span class="p">)</span>
        <span class="c1"># Height should be the same as the height of the OKX Premium Indicator Signal input card</span>
        <span class="n">bot_okx_signal_input_model_box</span> <span class="o">=</span> <span class="n">ui</span><span class="o">.</span><span class="n">form_card</span><span class="p">(</span>
            <span class="n">box</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">box</span><span class="p">,</span>
            <span class="n">items</span><span class="o">=</span><span class="p">[</span>
                <span class="n">ui</span><span class="o">.</span><span class="n">separator</span><span class="p">(</span><span class="n">label</span><span class="o">=</span><span class="s1">&#39;Input Model for Endpoint&#39;</span><span class="p">,</span> <span class="n">width</span><span class="o">=</span><span class="s1">&#39;300px&#39;</span><span class="p">),</span>
                <span class="n">ui</span><span class="o">.</span><span class="n">copyable_text</span><span class="p">(</span>
                    <span class="n">label</span><span class="o">=</span><span class="s1">&#39;&#39;</span><span class="p">,</span>
                    <span class="n">value</span><span class="o">=</span><span class="n">output_value</span><span class="p">,</span>
                    <span class="n">multiline</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
                    <span class="n">height</span><span class="o">=</span><span class="s1">&#39;1&#39;</span><span class="p">,</span>
                <span class="p">),</span>
                <span class="c1">#         ui.separator(label=&#39;A separator sections forms&#39;),</span>
                <span class="c1">#         ui.toggle(name=&#39;toggle&#39;, label=&#39;Toggle&#39;),</span>
                <span class="c1">#         ui.choice_group(name=&#39;choice_group&#39;, label=&#39;Choice group&#39;, choices=[</span>
                <span class="c1">#             ui.choice(name=x, label=x) for x in [&#39;Egg&#39;, &#39;Bacon&#39;, &#39;Spam&#39;]</span>
                <span class="c1">#         ]),</span>
                <span class="c1">#         ui.dropdown(name=&#39;dropdown1&#39;, label=&#39;Dropdown&#39;, choices=[</span>
                <span class="c1">#             ui.choice(name=x, label=x) for x in [&#39;Egg&#39;, &#39;Bacon&#39;, &#39;Spam&#39;]</span>
                <span class="c1">#         ]),</span>
                <span class="c1">#</span>
                <span class="c1">#         ui.slider(name=&#39;slider&#39;, label=&#39;Slider&#39;),</span>
                <span class="c1">#         ui.range_slider(name=&#39;range_slider&#39;, label=&#39;Range slider&#39;, max=99),</span>
                <span class="c1">#         ui.file_upload(name=&#39;file_upload&#39;, label=&#39;File upload&#39;),</span>
                <span class="c1">#         ui.tabs(name=&#39;tabs&#39;, items=[</span>
                <span class="c1">#             ui.tab(name=&#39;email&#39;, label=&#39;Mail&#39;, icon=&#39;Mail&#39;),</span>
                <span class="c1">#             ui.tab(name=&#39;events&#39;, label=&#39;Events&#39;, icon=&#39;Calendar&#39;),</span>
                <span class="c1">#             ui.tab(name=&#39;spam&#39;, label=&#39;Spam&#39;),</span>
                <span class="c1">#         ]),</span>
                <span class="c1">#         ui.stepper(name=&#39;stepper&#39;, items=[</span>
                <span class="c1">#             ui.step(label=&#39;Step 1&#39;, icon=&#39;MailLowImportance&#39;, done=True),</span>
                <span class="c1">#             ui.step(label=&#39;Step 2&#39;, icon=&#39;TaskManagerMirrored&#39;),</span>
                <span class="c1">#             ui.step(label=&#39;Step 3&#39;, icon=&#39;Cafe&#39;),</span>
                <span class="c1">#         ]),</span>
                <span class="c1">#         ui.expander(name=&#39;expander&#39;, label=&#39;Expander&#39;, items=[</span>
                <span class="c1">#             ui.combobox(name=&#39;combobox&#39;, label=&#39;Combobox&#39;, choices=[&#39;Choice 1&#39;, &#39;Choice 2&#39;, &#39;Choice 3&#39;]),</span>
                <span class="c1">#             ui.slider(name=&#39;slider&#39;, label=&#39;Slider&#39;),</span>
                <span class="c1">#             ui.range_slider(name=&#39;range_slider&#39;, label=&#39;Range slider&#39;, max=99),</span>
                <span class="c1">#             ui.spinbox(name=&#39;spinbox&#39;, label=&#39;Spinbox&#39;),</span>
                <span class="c1">#         ]),</span>
                <span class="c1">#         ui.picker(name=&#39;picker&#39;, label=&#39;Picker&#39;, choices=[</span>
                <span class="c1">#             ui.choice(&#39;choice1&#39;, label=&#39;Choice 1&#39;),</span>
                <span class="c1">#             ui.choice(&#39;choice2&#39;, label=&#39;Choice 2&#39;),</span>
                <span class="c1">#             ui.choice(&#39;choice3&#39;, label=&#39;Choice 3&#39;),</span>
                <span class="c1">#         ]),</span>
                <span class="c1">#         ui.button(name=&#39;show_inputs&#39;, label=&#39;Submit&#39;, primary=True),</span>
            <span class="p">])</span>
        <span class="n">bot_okx_signal_output_response_card</span> <span class="o">=</span> <span class="n">ui</span><span class="o">.</span><span class="n">form_card</span><span class="p">(</span>
            <span class="n">box</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">box</span><span class="p">,</span>
            <span class="n">items</span><span class="o">=</span><span class="p">[</span>
                <span class="n">ui</span><span class="o">.</span><span class="n">separator</span><span class="p">(</span><span class="n">label</span><span class="o">=</span><span class="s1">&#39;Output Response&#39;</span><span class="p">,</span> <span class="n">width</span><span class="o">=</span><span class="s1">&#39;300px&#39;</span><span class="p">),</span>
                <span class="n">ui</span><span class="o">.</span><span class="n">copyable_text</span><span class="p">(</span>
                    <span class="n">label</span><span class="o">=</span><span class="s1">&#39;&#39;</span><span class="p">,</span>
                    <span class="n">value</span><span class="o">=</span><span class="s1">&#39;output response will appear here&#39;</span><span class="p">,</span>
                    <span class="n">multiline</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
                    <span class="n">height</span><span class="o">=</span><span class="s1">&#39;1&#39;</span>
                <span class="p">),</span>
            <span class="p">])</span>

        <span class="k">await</span> <span class="n">add_card</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">q</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">card_name</span> <span class="o">+</span> <span class="s1">&#39;_okx_signal_inputs&#39;</span><span class="p">,</span> <span class="n">bot_okx_signal_inputs</span><span class="p">)</span>
        <span class="k">await</span> <span class="n">add_card</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">q</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">card_name</span> <span class="o">+</span> <span class="s1">&#39;_okx_signal_input_model_box&#39;</span><span class="p">,</span> <span class="n">bot_okx_signal_input_model_box</span><span class="p">)</span>
        <span class="k">await</span> <span class="n">add_card</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">q</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">card_name</span> <span class="o">+</span> <span class="s1">&#39;_okx_signal_output_response_card&#39;</span><span class="p">,</span> <span class="n">bot_okx_signal_output_response_card</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">q</span><span class="o">.</span><span class="n">client</span><span class="o">.</span><span class="n">OKX_Manual_ControlsWidget_card_name</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">card_name</span>

        <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">q</span><span class="o">.</span><span class="n">page</span><span class="o">.</span><span class="n">save</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_initialized</span> <span class="o">=</span> <span class="kc">True</span></div>


<div class="viewcode-block" id="OKX_Premium_Indicator_Handler_Widget.update_cards">
<a class="viewcode-back" href="../../../../h2o_dashboard.pages.okx_dashbaord_page.okx_antbot_okx_premium_indicator_handler.html#h2o_dashboard.pages.okx_dashbaord_page.okx_antbot_okx_premium_indicator_handler.OKX_Premium_Indicator_Handler_Widget.update_cards">[docs]</a>
    <span class="k">async</span> <span class="k">def</span> <span class="nf">update_cards</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">_update_stream</span><span class="p">()</span>
        <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">q</span><span class="o">.</span><span class="n">page</span><span class="o">.</span><span class="n">save</span><span class="p">()</span></div>
</div>



<span class="c1">#  input_form = InstIdSignalRequestForm(</span>
<span class="c1">#         InstIdAPIKey=&quot;eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJydWJlbkBjYXJib255bC5vcmciLCJpZCI6Ilk5UUVOdExIZThiMnRwVEVuNVRnNllZRUxsZDIiLCJyb2xlIjoidHJhZGluZ19pbnN0cnVtZW50IiwiaW5zdElEIjoiQlRDLVVTRC0yNDAyMDkifQ.lVxzjoxGGwH_qzrRu1uMFklEGRQjpgHMKgJo44J1_BE&quot;,</span>
<span class="c1">#         OKXSignalInput=OKXSignalInput(</span>
<span class="c1">#             instID=&quot;BTC-USD-240209&quot;,</span>
<span class="c1">#         )</span>
<span class="c1">#     )</span>
<span class="c1"># result = requests.post(&quot;http://localhost:8080/okx_antbot_signal&quot;,</span>
<span class="c1">#                        json=input_form.model_dump())</span>
<span class="c1"># print(f&#39;{result = }&#39;)</span>
<span class="c1"># print(f&#39;{result.json() = }&#39;)</span>
<span class="c1">#</span>
<span class="c1"># return</span>
<div class="viewcode-block" id="on_instID_selection">
<a class="viewcode-back" href="../../../../h2o_dashboard.pages.okx_dashbaord_page.okx_antbot_okx_premium_indicator_handler.html#h2o_dashboard.pages.okx_dashbaord_page.okx_antbot_okx_premium_indicator_handler.on_instID_selection">[docs]</a>
<span class="nd">@on</span><span class="p">(</span><span class="s1">&#39;okx_dashboard_page_okx_premium_indicator_instID&#39;</span><span class="p">)</span>
<span class="k">async</span> <span class="k">def</span> <span class="nf">on_instID_selection</span><span class="p">(</span><span class="n">q</span><span class="p">:</span> <span class="n">Q</span><span class="p">):</span>
    <span class="n">copy_expando</span><span class="p">(</span><span class="n">q</span><span class="o">.</span><span class="n">args</span><span class="p">,</span> <span class="n">q</span><span class="o">.</span><span class="n">client</span><span class="p">)</span>
    <span class="k">try</span><span class="p">:</span>
        <span class="c1"># Lets show the rest of the ticker/instID information in the Output Response card</span>
        <span class="n">instID</span> <span class="o">=</span> <span class="n">q</span><span class="o">.</span><span class="n">client</span><span class="o">.</span><span class="n">okx_dashboard_page_okx_premium_indicator_instID</span>
        <span class="n">instruments_searcher</span><span class="p">:</span> <span class="n">InstrumentSearcher</span> <span class="o">=</span> <span class="k">await</span> <span class="n">get_instruments_searcher_from_redis</span><span class="p">(</span><span class="n">q</span><span class="o">.</span><span class="n">client</span><span class="o">.</span><span class="n">async_redis</span><span class="p">,</span>
                                                                                             <span class="n">instType</span><span class="o">=</span><span class="n">ENFORCED_INSTRUMENT_TYPE</span><span class="p">)</span>
        <span class="n">instrument_ticker</span> <span class="o">=</span> <span class="n">instruments_searcher</span><span class="o">.</span><span class="n">find_by_instId</span><span class="p">(</span><span class="n">instID</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">instrument_ticker</span><span class="p">:</span>
            <span class="n">q</span><span class="o">.</span><span class="n">client</span><span class="o">.</span><span class="n">okx_dashboard_page_instrument_ticker</span> <span class="o">=</span> <span class="n">instrument_ticker</span>
            <span class="n">output_response_card</span> <span class="o">=</span> <span class="n">q</span><span class="o">.</span><span class="n">page</span><span class="p">[</span>
                <span class="n">q</span><span class="o">.</span><span class="n">client</span><span class="o">.</span><span class="n">OKX_Manual_ControlsWidget_card_name</span> <span class="o">+</span> <span class="s1">&#39;_okx_signal_output_response_card&#39;</span><span class="p">]</span>

            <span class="n">returning_txt_value</span> <span class="o">=</span> <span class="sa">f</span><span class="s1">&#39;Instrument Ticker Information:</span><span class="se">\n\n</span><span class="s1">&#39;</span>
            <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">instrument_ticker</span><span class="o">.</span><span class="n">model_dump</span><span class="p">()</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
                <span class="n">returning_txt_value</span> <span class="o">+=</span> <span class="sa">f</span><span class="s1">&#39;</span><span class="si">{</span><span class="n">k</span><span class="si">}</span><span class="s1">: </span><span class="si">{</span><span class="n">pprint</span><span class="o">.</span><span class="n">pformat</span><span class="p">(</span><span class="n">v</span><span class="p">,</span><span class="w"> </span><span class="n">compact</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span><span class="w"> </span><span class="n">sort_dicts</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span><span class="w"> </span><span class="n">width</span><span class="o">=</span><span class="mi">100</span><span class="p">,</span><span class="w"> </span><span class="n">depth</span><span class="o">=</span><span class="mi">5</span><span class="p">)</span><span class="si">}</span><span class="se">\n</span><span class="s1">&#39;</span>

            <span class="n">output_response_card</span><span class="o">.</span><span class="n">items</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">copyable_text</span><span class="o">.</span><span class="n">value</span> <span class="o">=</span> <span class="n">returning_txt_value</span>
            <span class="k">await</span> <span class="n">q</span><span class="o">.</span><span class="n">page</span><span class="o">.</span><span class="n">save</span><span class="p">()</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">q</span><span class="o">.</span><span class="n">client</span><span class="o">.</span><span class="n">okx_dashboard_page_instrument_ticker</span> <span class="o">=</span> <span class="kc">None</span>
            <span class="n">output_response_card</span> <span class="o">=</span> <span class="n">q</span><span class="o">.</span><span class="n">page</span><span class="p">[</span>
                <span class="n">q</span><span class="o">.</span><span class="n">client</span><span class="o">.</span><span class="n">OKX_Manual_ControlsWidget_card_name</span> <span class="o">+</span> <span class="s1">&#39;_okx_signal_output_response_card&#39;</span><span class="p">]</span>
            <span class="n">output_response_card</span><span class="o">.</span><span class="n">items</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">copyable_text</span><span class="o">.</span><span class="n">value</span> <span class="o">=</span> <span class="sa">f</span><span class="s1">&#39;No instrument ticker found for </span><span class="si">{</span><span class="n">instID</span><span class="si">}</span><span class="s1">&#39;</span>
            <span class="k">await</span> <span class="n">q</span><span class="o">.</span><span class="n">page</span><span class="o">.</span><span class="n">save</span><span class="p">()</span>


    <span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
        <span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s1">&#39;</span><span class="si">{</span><span class="n">e</span><span class="w"> </span><span class="si">= }</span><span class="s1">&#39;</span><span class="p">)</span>
        <span class="n">output_response_card</span> <span class="o">=</span> <span class="n">q</span><span class="o">.</span><span class="n">page</span><span class="p">[</span><span class="n">q</span><span class="o">.</span><span class="n">client</span><span class="o">.</span><span class="n">OKX_Manual_ControlsWidget_card_name</span> <span class="o">+</span> <span class="s1">&#39;_okx_signal_output_response_card&#39;</span><span class="p">]</span>
        <span class="n">output_response_card</span><span class="o">.</span><span class="n">items</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">copyable_text</span><span class="o">.</span><span class="n">value</span> <span class="o">=</span> <span class="n">pprint</span><span class="o">.</span><span class="n">pformat</span><span class="p">(</span><span class="n">e</span><span class="p">,</span> <span class="n">compact</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">sort_dicts</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
                                                                           <span class="n">width</span><span class="o">=</span><span class="mi">100</span><span class="p">,</span> <span class="n">depth</span><span class="o">=</span><span class="mi">5</span><span class="p">)</span>
        <span class="k">await</span> <span class="n">q</span><span class="o">.</span><span class="n">page</span><span class="o">.</span><span class="n">save</span><span class="p">()</span>
        <span class="k">return</span></div>



<div class="viewcode-block" id="okx_signal_validate_inputs">
<a class="viewcode-back" href="../../../../h2o_dashboard.pages.okx_dashbaord_page.okx_antbot_okx_premium_indicator_handler.html#h2o_dashboard.pages.okx_dashbaord_page.okx_antbot_okx_premium_indicator_handler.okx_signal_validate_inputs">[docs]</a>
<span class="nd">@on</span><span class="p">(</span><span class="s1">&#39;okx_dashboard_page_okx_premium_indicator_validate_inputs&#39;</span><span class="p">)</span>
<span class="k">async</span> <span class="k">def</span> <span class="nf">okx_signal_validate_inputs</span><span class="p">(</span><span class="n">q</span><span class="p">:</span> <span class="n">Q</span><span class="p">):</span>
    <span class="c1"># Copy the inputs from the args if found to the client</span>
    <span class="n">copy_expando</span><span class="p">(</span><span class="n">q</span><span class="o">.</span><span class="n">args</span><span class="p">,</span> <span class="n">q</span><span class="o">.</span><span class="n">client</span><span class="p">)</span>
    <span class="n">okx_signal_params</span> <span class="o">=</span> <span class="p">{</span><span class="n">att</span><span class="p">:</span> <span class="n">q</span><span class="o">.</span><span class="n">client</span><span class="p">[</span><span class="sa">f</span><span class="s1">&#39;okx_dashboard_page_okx_premium_indicator_</span><span class="si">{</span><span class="n">att</span><span class="si">}</span><span class="s1">&#39;</span><span class="p">]</span> <span class="k">for</span> <span class="n">att</span> <span class="ow">in</span>
                         <span class="n">OKX_SIGNAL_INPUT_KEYS</span><span class="p">}</span>

    <span class="k">try</span><span class="p">:</span>
        <span class="c1"># Clean the OKX Signal params</span>
        <span class="n">keys_to_remove</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">okx_signal_params</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
            <span class="k">if</span> <span class="n">v</span> <span class="o">==</span> <span class="s1">&#39;&#39;</span> <span class="ow">or</span> <span class="n">v</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                <span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s1">&#39;Warning: </span><span class="si">{</span><span class="n">k</span><span class="si">}</span><span class="s1"> is empty&#39;</span><span class="p">)</span>
                <span class="n">keys_to_remove</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">k</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">keys_to_remove</span><span class="p">:</span>
            <span class="n">okx_signal_params</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="n">k</span><span class="p">)</span>
        <span class="n">okx_signal</span> <span class="o">=</span> <span class="n">OKXSignalInput</span><span class="p">(</span><span class="o">**</span><span class="n">okx_signal_params</span><span class="p">)</span>
        <span class="n">q</span><span class="o">.</span><span class="n">client</span><span class="o">.</span><span class="n">okx_dashboard_page_okx_signal_input</span> <span class="o">=</span> <span class="n">okx_signal</span>

        <span class="k">try</span><span class="p">:</span>
            <span class="n">validated_inputs</span> <span class="o">=</span> <span class="k">await</span> <span class="n">validate_okx_signal_params</span><span class="p">(</span><span class="n">okx_signal</span><span class="p">)</span>

            <span class="n">return_txt_value</span> <span class="o">=</span> <span class="p">(</span><span class="sa">f</span><span class="s1">&#39;Inputs have been validated by Pydantic, furthermore, all transformation done to &#39;</span>
                                <span class="sa">f</span><span class="s1">&#39;validate the input from inside the OKXSignalHandler have passed. Make sure &#39;</span>
                                <span class="sa">f</span><span class="s1">&#39;variables have their expected values:</span><span class="se">\n\n</span><span class="s1">&#39;</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">validated_inputs</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
                <span class="n">return_txt_value</span> <span class="o">+=</span> <span class="sa">f</span><span class="s1">&#39;</span><span class="si">{</span><span class="n">k</span><span class="si">}</span><span class="s1">: </span><span class="si">{</span><span class="n">v</span><span class="si">}</span><span class="se">\n</span><span class="s1">&#39;</span>

            <span class="n">bot_okx_signal_input_model_box</span><span class="p">:</span> <span class="n">ui</span><span class="o">.</span><span class="n">form_card</span> <span class="o">=</span> <span class="n">q</span><span class="o">.</span><span class="n">page</span><span class="p">[</span>
                <span class="n">q</span><span class="o">.</span><span class="n">client</span><span class="o">.</span><span class="n">OKX_Manual_ControlsWidget_card_name</span> <span class="o">+</span> <span class="s1">&#39;_okx_signal_input_model_box&#39;</span><span class="p">]</span>
            <span class="n">output_value</span> <span class="o">=</span> <span class="s2">&quot;When ready or in doubt, </span><span class="se">\n</span><span class="s2">  press the `Validate Input Model` button&quot;</span> \
                <span class="k">if</span> <span class="ow">not</span> <span class="n">okx_signal</span> <span class="k">else</span> <span class="n">okx_signal</span><span class="o">.</span><span class="n">model_dump</span><span class="p">()</span>
            <span class="c1"># Pretty output the pydantic model without reordering the keys</span>
            <span class="n">bot_okx_signal_input_model_box</span><span class="o">.</span><span class="n">items</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">copyable_text</span><span class="o">.</span><span class="n">value</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">output_value</span><span class="p">)</span> <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span>
                <span class="n">output_value</span><span class="p">,</span>
                <span class="nb">dict</span><span class="p">)</span> <span class="k">else</span> <span class="n">pprint</span><span class="o">.</span><span class="n">pformat</span><span class="p">(</span>
                <span class="n">output_value</span><span class="p">,</span> <span class="n">compact</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">sort_dicts</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
                <span class="n">width</span><span class="o">=</span><span class="mi">100</span><span class="p">,</span> <span class="n">depth</span><span class="o">=</span><span class="mi">5</span><span class="p">)</span>
            <span class="n">output_response_card</span> <span class="o">=</span> <span class="n">q</span><span class="o">.</span><span class="n">page</span><span class="p">[</span>
                <span class="n">q</span><span class="o">.</span><span class="n">client</span><span class="o">.</span><span class="n">OKX_Manual_ControlsWidget_card_name</span> <span class="o">+</span> <span class="s1">&#39;_okx_signal_output_response_card&#39;</span><span class="p">]</span>
            <span class="n">output_response_card</span><span class="o">.</span><span class="n">items</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">copyable_text</span><span class="o">.</span><span class="n">value</span> <span class="o">=</span> <span class="n">return_txt_value</span>
            <span class="k">await</span> <span class="n">q</span><span class="o">.</span><span class="n">page</span><span class="o">.</span><span class="n">save</span><span class="p">()</span>
            <span class="k">return</span> <span class="kc">True</span>
        <span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
            <span class="k">raise</span> <span class="n">e</span>

    <span class="k">except</span> <span class="n">ValidationError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
        <span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;</span><span class="si">{</span><span class="n">e</span><span class="w"> </span><span class="si">= }</span><span class="s2">&quot;</span><span class="p">)</span>
        <span class="c1"># Parse and format the errors</span>
        <span class="n">errors</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">for</span> <span class="n">error</span> <span class="ow">in</span> <span class="n">e</span><span class="o">.</span><span class="n">errors</span><span class="p">():</span>
            <span class="n">field</span> <span class="o">=</span> <span class="n">error</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;loc&#39;</span><span class="p">,</span> <span class="p">[])[</span><span class="mi">0</span><span class="p">]</span>
            <span class="n">msg</span> <span class="o">=</span> <span class="n">error</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;msg&#39;</span><span class="p">,</span> <span class="s1">&#39;&#39;</span><span class="p">)</span>
            <span class="n">error_type</span> <span class="o">=</span> <span class="n">error</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;type&#39;</span><span class="p">,</span> <span class="s1">&#39;&#39;</span><span class="p">)</span>
            <span class="n">input_value</span> <span class="o">=</span> <span class="n">error</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;input_value&#39;</span><span class="p">,</span> <span class="s1">&#39;&#39;</span><span class="p">)</span>
            <span class="n">errors</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;Field: </span><span class="si">{</span><span class="n">field</span><span class="si">}</span><span class="s2">, Error: </span><span class="si">{</span><span class="n">msg</span><span class="si">}</span><span class="s2">, Type: </span><span class="si">{</span><span class="n">error_type</span><span class="si">}</span><span class="s2">, Input Value: </span><span class="si">{</span><span class="n">input_value</span><span class="si">}</span><span class="s2">&quot;</span><span class="p">)</span>

        <span class="c1"># Create a card to display the error</span>
        <span class="n">return_txt_value</span> <span class="o">=</span> <span class="sa">f</span><span class="s1">&#39;Validation Errors:</span><span class="se">\n\n\n</span><span class="s1">&#39;</span>
        <span class="k">for</span> <span class="n">error</span> <span class="ow">in</span> <span class="n">errors</span><span class="p">:</span>
            <span class="n">return_txt_value</span> <span class="o">+=</span> <span class="sa">f</span><span class="s1">&#39;• </span><span class="si">{</span><span class="n">error</span><span class="si">}</span><span class="se">\n</span><span class="s1">&#39;</span>

        <span class="n">output_response_card</span> <span class="o">=</span> <span class="n">q</span><span class="o">.</span><span class="n">page</span><span class="p">[</span><span class="n">q</span><span class="o">.</span><span class="n">client</span><span class="o">.</span><span class="n">OKX_Manual_ControlsWidget_card_name</span> <span class="o">+</span> <span class="s1">&#39;_okx_signal_output_response_card&#39;</span><span class="p">]</span>
        <span class="n">output_response_card</span><span class="o">.</span><span class="n">items</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">copyable_text</span><span class="o">.</span><span class="n">value</span> <span class="o">=</span> <span class="n">return_txt_value</span>
    <span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
        <span class="n">output_response_card</span> <span class="o">=</span> <span class="n">q</span><span class="o">.</span><span class="n">page</span><span class="p">[</span><span class="n">q</span><span class="o">.</span><span class="n">client</span><span class="o">.</span><span class="n">OKX_Manual_ControlsWidget_card_name</span> <span class="o">+</span> <span class="s1">&#39;_okx_signal_output_response_card&#39;</span><span class="p">]</span>
        <span class="n">output_response_card</span><span class="o">.</span><span class="n">items</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">copyable_text</span><span class="o">.</span><span class="n">value</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)</span>

    <span class="k">await</span> <span class="n">q</span><span class="o">.</span><span class="n">page</span><span class="o">.</span><span class="n">save</span><span class="p">()</span>
    <span class="k">return</span></div>



<div class="viewcode-block" id="submit_okx_signal">
<a class="viewcode-back" href="../../../../h2o_dashboard.pages.okx_dashbaord_page.okx_antbot_okx_premium_indicator_handler.html#h2o_dashboard.pages.okx_dashbaord_page.okx_antbot_okx_premium_indicator_handler.submit_okx_signal">[docs]</a>
<span class="nd">@on</span><span class="p">(</span><span class="s1">&#39;okx_dashboard_page_okx_premium_indicator_submit_okx_signal&#39;</span><span class="p">)</span>
<span class="k">async</span> <span class="k">def</span> <span class="nf">submit_okx_signal</span><span class="p">(</span><span class="n">q</span><span class="p">:</span> <span class="n">Q</span><span class="p">):</span>
    <span class="n">output_response_card</span> <span class="o">=</span> <span class="n">q</span><span class="o">.</span><span class="n">page</span><span class="p">[</span><span class="n">q</span><span class="o">.</span><span class="n">client</span><span class="o">.</span><span class="n">OKX_Manual_ControlsWidget_card_name</span> <span class="o">+</span> <span class="s1">&#39;_okx_signal_output_response_card&#39;</span><span class="p">]</span>

    <span class="n">okx_signal_txt_header</span> <span class="o">=</span> <span class="s1">&#39;OKX Signal Response:</span><span class="se">\n\n</span><span class="s1">&#39;</span>

    <span class="c1"># First validate the inputs</span>
    <span class="k">try</span><span class="p">:</span>
        <span class="n">successful_validation</span> <span class="o">=</span> <span class="k">await</span> <span class="n">okx_signal_validate_inputs</span><span class="p">(</span><span class="n">q</span><span class="p">)</span>
        <span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s1">&#39;</span><span class="si">{</span><span class="n">successful_validation</span><span class="si">= }</span><span class="s1">&#39;</span><span class="p">)</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">successful_validation</span><span class="p">:</span>
            <span class="k">return</span>
    <span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
        <span class="n">output_response_card</span><span class="o">.</span><span class="n">items</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">copyable_text</span><span class="o">.</span><span class="n">value</span> <span class="o">=</span> <span class="sa">f</span><span class="s2">&quot;</span><span class="si">{</span><span class="n">e</span><span class="w"> </span><span class="si">= }</span><span class="s2">&quot;</span>
        <span class="k">await</span> <span class="n">q</span><span class="o">.</span><span class="n">page</span><span class="o">.</span><span class="n">save</span><span class="p">()</span>
        <span class="k">return</span>

    <span class="n">okx_signal</span> <span class="o">=</span> <span class="n">q</span><span class="o">.</span><span class="n">client</span><span class="o">.</span><span class="n">okx_dashboard_page_okx_signal_input</span>
    <span class="k">if</span> <span class="ow">not</span> <span class="n">okx_signal</span><span class="p">:</span>
        <span class="n">output_response_card</span><span class="o">.</span><span class="n">items</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">copyable_text</span><span class="o">.</span><span class="n">value</span> <span class="o">=</span> <span class="s1">&#39;No OKX Signal found&#39;</span>
        <span class="k">await</span> <span class="n">q</span><span class="o">.</span><span class="n">page</span><span class="o">.</span><span class="n">save</span><span class="p">()</span>
        <span class="k">return</span>
    <span class="k">try</span><span class="p">:</span>
        <span class="n">output_response_card</span><span class="o">.</span><span class="n">items</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">copyable_text</span><span class="o">.</span><span class="n">value</span> <span class="o">=</span> <span class="sa">f</span><span class="s2">&quot;Submitting OKX Signal Handler Request...&quot;</span>
        <span class="k">await</span> <span class="n">q</span><span class="o">.</span><span class="n">page</span><span class="o">.</span><span class="n">save</span><span class="p">()</span>
        <span class="n">signal_response</span> <span class="o">=</span> <span class="k">await</span> <span class="n">okx_signal_handler</span><span class="p">(</span>
            <span class="o">**</span><span class="n">okx_signal</span><span class="o">.</span><span class="n">model_dump</span><span class="p">()</span>
        <span class="p">)</span>
        <span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s1">&#39;</span><span class="si">{</span><span class="n">signal_response</span><span class="si">= }</span><span class="s1">&#39;</span><span class="p">)</span>
        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">signal_response</span><span class="p">,</span> <span class="nb">dict</span><span class="p">)</span> <span class="ow">and</span> <span class="p">(</span><span class="n">signal_response</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;error&#39;</span><span class="p">)</span> <span class="ow">or</span> <span class="n">signal_response</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;red_button&#39;</span><span class="p">)):</span>
            <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;Is instance of dict&#39;</span><span class="p">)</span>
            <span class="n">output_response_card</span><span class="o">.</span><span class="n">items</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">copyable_text</span><span class="o">.</span><span class="n">value</span> <span class="o">=</span> <span class="n">okx_signal_txt_header</span> <span class="o">+</span> <span class="n">pprint</span><span class="o">.</span><span class="n">pformat</span><span class="p">(</span><span class="n">signal_response</span><span class="p">,</span>
                                                                                                       <span class="n">compact</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
                                                                                                       <span class="n">sort_dicts</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
                                                                                                       <span class="n">width</span><span class="o">=</span><span class="mi">100</span><span class="p">,</span>
                                                                                                       <span class="n">depth</span><span class="o">=</span><span class="mi">5</span><span class="p">)</span>
        <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">signal_response</span><span class="p">,</span> <span class="n">InstrumentStatusReport</span><span class="p">):</span>
            <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;Is instance of InstrumentStatusReport&#39;</span><span class="p">)</span>
            <span class="n">output_response_card</span><span class="o">.</span><span class="n">items</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">copyable_text</span><span class="o">.</span><span class="n">value</span> <span class="o">=</span> <span class="n">okx_signal_txt_header</span> <span class="o">+</span> <span class="n">pprint</span><span class="o">.</span><span class="n">pformat</span><span class="p">(</span><span class="n">signal_response</span><span class="p">,</span>
                                                                                                       <span class="n">compact</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
                                                                                                       <span class="n">sort_dicts</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
                                                                                                       <span class="n">width</span><span class="o">=</span><span class="mi">100</span><span class="p">,</span>
                                                                                                       <span class="n">depth</span><span class="o">=</span><span class="mi">5</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;Is instance of else&#39;</span><span class="p">)</span>
            <span class="n">output_response_card</span><span class="o">.</span><span class="n">items</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">copyable_text</span><span class="o">.</span><span class="n">value</span> <span class="o">=</span> <span class="n">okx_signal_txt_header</span> <span class="o">+</span> <span class="n">pprint</span><span class="o">.</span><span class="n">pformat</span><span class="p">(</span><span class="n">signal_response</span><span class="p">,</span>
                                                                                                       <span class="n">compact</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
                                                                                                       <span class="n">sort_dicts</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
                                                                                                       <span class="n">width</span><span class="o">=</span><span class="mi">100</span><span class="p">,</span>
                                                                                                       <span class="n">depth</span><span class="o">=</span><span class="mi">5</span><span class="p">)</span>
    <span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
        <span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s1">&#39;</span><span class="si">{</span><span class="n">e</span><span class="w"> </span><span class="si">= }</span><span class="s1">&#39;</span><span class="p">)</span>
        <span class="n">output_response_card</span><span class="o">.</span><span class="n">items</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">copyable_text</span><span class="o">.</span><span class="n">value</span> <span class="o">=</span> <span class="sa">f</span><span class="s2">&quot;</span><span class="si">{</span><span class="n">e</span><span class="w"> </span><span class="si">= }</span><span class="s2">&quot;</span>
        <span class="k">await</span> <span class="n">q</span><span class="o">.</span><span class="n">page</span><span class="o">.</span><span class="n">save</span><span class="p">()</span>
        <span class="k">return</span>

    <span class="k">await</span> <span class="n">q</span><span class="o">.</span><span class="n">page</span><span class="o">.</span><span class="n">save</span><span class="p">()</span></div>



<div class="viewcode-block" id="generate_tv_payload">
<a class="viewcode-back" href="../../../../h2o_dashboard.pages.okx_dashbaord_page.okx_antbot_okx_premium_indicator_handler.html#h2o_dashboard.pages.okx_dashbaord_page.okx_antbot_okx_premium_indicator_handler.generate_tv_payload">[docs]</a>
<span class="nd">@on</span><span class="p">(</span><span class="s1">&#39;okx_dashboard_page_okx_premium_indicator_generate_tv_payload&#39;</span><span class="p">)</span>
<span class="k">async</span> <span class="k">def</span> <span class="nf">generate_tv_payload</span><span class="p">(</span><span class="n">q</span><span class="p">:</span> <span class="n">Q</span><span class="p">):</span>
    <span class="n">output_response_card</span> <span class="o">=</span> <span class="n">q</span><span class="o">.</span><span class="n">page</span><span class="p">[</span><span class="n">q</span><span class="o">.</span><span class="n">client</span><span class="o">.</span><span class="n">OKX_Manual_ControlsWidget_card_name</span> <span class="o">+</span> <span class="s1">&#39;_okx_signal_output_response_card&#39;</span><span class="p">]</span>
    <span class="n">okx_signal_txt_header</span> <span class="o">=</span> <span class="s1">&#39;TV Payload Response:</span><span class="se">\n\n</span><span class="s1">&#39;</span>

    <span class="k">try</span><span class="p">:</span>
        <span class="n">output_response_card</span><span class="o">.</span><span class="n">items</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">copyable_text</span><span class="o">.</span><span class="n">value</span> <span class="o">=</span> <span class="sa">f</span><span class="s2">&quot;Generating TV Payload...&quot;</span>
        <span class="k">await</span> <span class="n">q</span><span class="o">.</span><span class="n">page</span><span class="o">.</span><span class="n">save</span><span class="p">()</span>

        <span class="k">if</span> <span class="n">q</span><span class="o">.</span><span class="n">client</span><span class="o">.</span><span class="n">token</span><span class="p">:</span>
            <span class="n">auth_response</span> <span class="o">=</span> <span class="k">await</span> <span class="n">check_str_token_validity</span><span class="p">(</span><span class="n">q</span><span class="o">.</span><span class="n">client</span><span class="o">.</span><span class="n">token</span><span class="p">)</span>
            <span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s1">&#39;</span><span class="si">{</span><span class="n">auth_response</span><span class="w"> </span><span class="si">= }</span><span class="s1">&#39;</span><span class="p">)</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="n">auth_response</span><span class="p">:</span>
                <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Token is invalid, please reload the page and log in again&quot;</span><span class="p">)</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">q</span><span class="o">.</span><span class="n">client</span><span class="o">.</span><span class="n">okx_dashboard_page_okx_premium_indicator_instID</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Choose an instrument ID first&quot;</span><span class="p">)</span>
        <span class="c1"># Curl create_instrument_api_key using the InstIdAPIKeyCreationRequestForm model</span>
        <span class="n">request_payload</span> <span class="o">=</span> <span class="n">InstIdAPIKeyCreationRequestForm</span><span class="p">(</span>
            <span class="n">username</span><span class="o">=</span><span class="n">q</span><span class="o">.</span><span class="n">client</span><span class="o">.</span><span class="n">email</span><span class="p">,</span>
            <span class="n">password</span><span class="o">=</span><span class="n">q</span><span class="o">.</span><span class="n">client</span><span class="o">.</span><span class="n">password</span><span class="p">,</span>
            <span class="n">instID</span><span class="o">=</span><span class="n">q</span><span class="o">.</span><span class="n">client</span><span class="o">.</span><span class="n">okx_dashboard_page_okx_premium_indicator_instID</span><span class="p">,</span>
            <span class="n">expire_time</span><span class="o">=</span><span class="kc">None</span>
        <span class="p">)</span>
        <span class="n">instrument_api_key_response</span> <span class="o">=</span> <span class="k">await</span> <span class="n">create_instrument_api_key</span><span class="p">(</span><span class="n">request_payload</span><span class="p">,</span> <span class="n">q</span><span class="o">.</span><span class="n">client</span><span class="o">.</span><span class="n">token</span><span class="p">)</span>

        <span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s1">&#39;</span><span class="si">{</span><span class="n">instrument_api_key_response</span><span class="w"> </span><span class="si">= }</span><span class="s1">&#39;</span><span class="p">)</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">instrument_api_key_response</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;access_token&#39;</span><span class="p">):</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Failed to create instrument API key&quot;</span><span class="p">)</span>

        <span class="n">request_model</span> <span class="o">=</span> <span class="k">await</span> <span class="n">on_premium_indicator_signal_selection</span><span class="p">(</span><span class="n">q</span><span class="p">,</span> <span class="n">only_return_request_model</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
        <span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s1">&#39;</span><span class="si">{</span><span class="n">request_model</span><span class="w"> </span><span class="si">= }</span><span class="s1">&#39;</span><span class="p">)</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">request_model</span><span class="p">:</span>
            <span class="k">return</span>

        <span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s1">&#39;</span><span class="si">{</span><span class="n">request_model</span><span class="w"> </span><span class="si">= }</span><span class="s1">&#39;</span><span class="p">)</span>
        <span class="n">request_model</span><span class="o">.</span><span class="n">InstIdAPIKey</span> <span class="o">=</span> <span class="n">instrument_api_key_response</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;access_token&#39;</span><span class="p">)</span>

        <span class="n">tradingview_payload</span> <span class="o">=</span> <span class="n">request_model</span><span class="o">.</span><span class="n">to_tradingview_json_payload</span><span class="p">()</span>
        <span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s1">&#39;</span><span class="si">{</span><span class="n">tradingview_payload</span><span class="w"> </span><span class="si">= }</span><span class="s1">&#39;</span><span class="p">)</span>
        <span class="c1"># Pretty print but keep json integrity meaning without the string quotes</span>

        <span class="n">output_response_card</span><span class="o">.</span><span class="n">items</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">copyable_text</span><span class="o">.</span><span class="n">value</span> <span class="o">=</span> <span class="n">tradingview_payload</span>
    <span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
        <span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s1">&#39;</span><span class="si">{</span><span class="n">e</span><span class="w"> </span><span class="si">= }</span><span class="s1">&#39;</span><span class="p">)</span>
        <span class="n">output_response_card</span><span class="o">.</span><span class="n">items</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">copyable_text</span><span class="o">.</span><span class="n">value</span> <span class="o">=</span> <span class="sa">f</span><span class="s2">&quot;</span><span class="si">{</span><span class="n">e</span><span class="w"> </span><span class="si">= }</span><span class="s2">&quot;</span>
        <span class="k">await</span> <span class="n">q</span><span class="o">.</span><span class="n">page</span><span class="o">.</span><span class="n">save</span><span class="p">()</span>
        <span class="k">return</span>

    <span class="k">await</span> <span class="n">q</span><span class="o">.</span><span class="n">page</span><span class="o">.</span><span class="n">save</span><span class="p">()</span></div>



<div class="viewcode-block" id="on_premium_indicator_signal_selection">
<a class="viewcode-back" href="../../../../h2o_dashboard.pages.okx_dashbaord_page.okx_antbot_okx_premium_indicator_handler.html#h2o_dashboard.pages.okx_dashbaord_page.okx_antbot_okx_premium_indicator_handler.on_premium_indicator_signal_selection">[docs]</a>
<span class="nd">@on</span><span class="p">(</span><span class="s1">&#39;okx_dashboard_page_okx_premium_indicator_Bullish&#39;</span><span class="p">)</span>
<span class="nd">@on</span><span class="p">(</span><span class="s1">&#39;okx_dashboard_page_okx_premium_indicator_Bearish&#39;</span><span class="p">)</span>
<span class="nd">@on</span><span class="p">(</span><span class="s1">&#39;okx_dashboard_page_okx_premium_indicator_Bullish_plus&#39;</span><span class="p">)</span>
<span class="nd">@on</span><span class="p">(</span><span class="s1">&#39;okx_dashboard_page_okx_premium_indicator_Bearish_plus&#39;</span><span class="p">)</span>
<span class="nd">@on</span><span class="p">(</span><span class="s1">&#39;okx_dashboard_page_okx_premium_indicator_Bullish_Exit&#39;</span><span class="p">)</span>
<span class="nd">@on</span><span class="p">(</span><span class="s1">&#39;okx_dashboard_page_okx_premium_indicator_Bearish_Exit&#39;</span><span class="p">)</span>
<span class="k">async</span> <span class="k">def</span> <span class="nf">on_premium_indicator_signal_selection</span><span class="p">(</span><span class="n">q</span><span class="p">:</span> <span class="n">Q</span><span class="p">,</span> <span class="n">only_return_request_model</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
    <span class="n">output_response_card</span> <span class="o">=</span> <span class="n">q</span><span class="o">.</span><span class="n">page</span><span class="p">[</span><span class="n">q</span><span class="o">.</span><span class="n">client</span><span class="o">.</span><span class="n">OKX_Manual_ControlsWidget_card_name</span> <span class="o">+</span> <span class="s1">&#39;_okx_signal_output_response_card&#39;</span><span class="p">]</span>
    <span class="n">okx_signal_txt_header</span> <span class="o">=</span> <span class="s1">&#39;OKX Premium Indicator Signal Response:</span><span class="se">\n\n</span><span class="s1">&#39;</span>

    <span class="n">premium_indicator_signal_params</span> <span class="o">=</span> <span class="p">{</span><span class="n">att</span><span class="p">:</span> <span class="n">q</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="sa">f</span><span class="s1">&#39;okx_dashboard_page_okx_premium_indicator_</span><span class="si">{</span><span class="n">att</span><span class="si">}</span><span class="s1">&#39;</span><span class="p">]</span> <span class="k">for</span> <span class="n">att</span> <span class="ow">in</span>
                                       <span class="n">OKX_PREMIUM_INDICATOR_SIGNAL_INPUT_KEYS</span><span class="p">}</span>
    <span class="n">cleaned_indicator_params</span> <span class="o">=</span> <span class="p">{</span><span class="n">k</span><span class="p">:</span> <span class="mi">1</span> <span class="k">if</span> <span class="n">v</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="k">else</span> <span class="mi">0</span> <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">premium_indicator_signal_params</span><span class="o">.</span><span class="n">items</span><span class="p">()}</span>
    <span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s1">&#39;</span><span class="si">{</span><span class="n">cleaned_indicator_params</span><span class="w"> </span><span class="si">= }</span><span class="s1">&#39;</span><span class="p">)</span>
    <span class="k">if</span> <span class="ow">not</span> <span class="n">only_return_request_model</span> <span class="ow">and</span> <span class="nb">sum</span><span class="p">(</span><span class="n">cleaned_indicator_params</span><span class="o">.</span><span class="n">values</span><span class="p">())</span> <span class="o">!=</span> <span class="mi">1</span><span class="p">:</span>
        <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Only one of the premium indicator signals should be True&quot;</span><span class="p">)</span>

    <span class="c1"># Now lets Validate the inputs for the OKX signal</span>
    <span class="k">try</span><span class="p">:</span>
        <span class="n">okx_premium_indicator_signals</span> <span class="o">=</span> <span class="n">PremiumIndicatorSignals</span><span class="p">(</span><span class="o">**</span><span class="n">cleaned_indicator_params</span><span class="p">)</span>

        <span class="n">successful_validation</span> <span class="o">=</span> <span class="k">await</span> <span class="n">okx_signal_validate_inputs</span><span class="p">(</span>
            <span class="n">q</span><span class="p">,</span>
            <span class="c1"># override_okx_signal_params=q.client.okx_dashboard_page_okx_signal_input</span>
        <span class="p">)</span>

        <span class="n">bot_okx_signal_input_model_box</span><span class="p">:</span> <span class="n">ui</span><span class="o">.</span><span class="n">form_card</span> <span class="o">=</span> <span class="n">q</span><span class="o">.</span><span class="n">page</span><span class="p">[</span>
            <span class="n">q</span><span class="o">.</span><span class="n">client</span><span class="o">.</span><span class="n">OKX_Manual_ControlsWidget_card_name</span> <span class="o">+</span> <span class="s1">&#39;_okx_signal_input_model_box&#39;</span><span class="p">]</span>
        <span class="n">input_values</span> <span class="o">=</span> <span class="sa">f</span><span class="s1">&#39;</span><span class="se">\n</span><span class="s1">Premium Indicator Signal:</span><span class="se">\n</span><span class="s1">&#39;</span>
        <span class="c1">#     input_values += f&#39;{k}: {v}\n&#39;</span>

        <span class="n">input_values</span> <span class="o">+=</span> <span class="n">pprint</span><span class="o">.</span><span class="n">pformat</span><span class="p">(</span><span class="n">cleaned_indicator_params</span><span class="p">,</span> <span class="n">compact</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">sort_dicts</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">width</span><span class="o">=</span><span class="mi">100</span><span class="p">,</span> <span class="n">depth</span><span class="o">=</span><span class="mi">5</span><span class="p">)</span>
        <span class="n">input_values</span> <span class="o">+=</span> <span class="s1">&#39;</span><span class="se">\n\n</span><span class="s1">&#39;</span>
        <span class="n">input_values</span> <span class="o">+=</span> <span class="sa">f</span><span class="s1">&#39;OKX Signal:</span><span class="se">\n</span><span class="s1">&#39;</span>
        <span class="n">input_values</span> <span class="o">+=</span> <span class="n">pprint</span><span class="o">.</span><span class="n">pformat</span><span class="p">(</span><span class="n">q</span><span class="o">.</span><span class="n">client</span><span class="o">.</span><span class="n">okx_dashboard_page_okx_signal_input</span><span class="o">.</span><span class="n">model_dump</span><span class="p">(),</span> <span class="n">compact</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
                                       <span class="n">sort_dicts</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">width</span><span class="o">=</span><span class="mi">100</span><span class="p">,</span> <span class="n">depth</span><span class="o">=</span><span class="mi">5</span><span class="p">)</span>

        <span class="n">bot_okx_signal_input_model_box</span><span class="o">.</span><span class="n">items</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">copyable_text</span><span class="o">.</span><span class="n">value</span> <span class="o">=</span> <span class="n">input_values</span>

        <span class="c1"># TODO the OKX SIGNAL  we need to transform the indicator signals to actionable okx_signal which is not done yet</span>
        <span class="c1">#   here thus okx_signal_validate_inputs does not validate inside the okx_signal_handler function, only outside</span>
        <span class="c1">#   through pydantic models</span>
        <span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s1">&#39;</span><span class="si">{</span><span class="n">successful_validation</span><span class="si">= }</span><span class="s1">&#39;</span><span class="p">)</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">successful_validation</span><span class="p">:</span>
            <span class="k">return</span>
        <span class="nb">print</span><span class="p">()</span>


    <span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
        <span class="n">output_response_card</span><span class="o">.</span><span class="n">items</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">copyable_text</span><span class="o">.</span><span class="n">value</span> <span class="o">=</span> <span class="sa">f</span><span class="s2">&quot;</span><span class="si">{</span><span class="n">e</span><span class="w"> </span><span class="si">= }</span><span class="s2">&quot;</span>
        <span class="k">await</span> <span class="n">q</span><span class="o">.</span><span class="n">page</span><span class="o">.</span><span class="n">save</span><span class="p">()</span>
        <span class="k">return</span>

    <span class="n">okx_signal</span> <span class="o">=</span> <span class="n">q</span><span class="o">.</span><span class="n">client</span><span class="o">.</span><span class="n">okx_dashboard_page_okx_signal_input</span>

    <span class="k">if</span> <span class="ow">not</span> <span class="n">okx_signal</span><span class="p">:</span>
        <span class="n">output_response_card</span><span class="o">.</span><span class="n">items</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">copyable_text</span><span class="o">.</span><span class="n">value</span> <span class="o">=</span> <span class="s1">&#39;No OKX Signal found&#39;</span>
        <span class="k">await</span> <span class="n">q</span><span class="o">.</span><span class="n">page</span><span class="o">.</span><span class="n">save</span><span class="p">()</span>
        <span class="k">return</span>

    <span class="c1"># Now lets Submit the OKX signal but this time to the OKX Premium Indicator Signal Handler</span>
    <span class="k">try</span><span class="p">:</span>
        <span class="n">output_response_card</span><span class="o">.</span><span class="n">items</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">copyable_text</span><span class="o">.</span><span class="n">value</span> <span class="o">=</span> <span class="sa">f</span><span class="s2">&quot;Submitting OKX Premium Indicator Signal Request...&quot;</span>
        <span class="k">await</span> <span class="n">q</span><span class="o">.</span><span class="n">page</span><span class="o">.</span><span class="n">save</span><span class="p">()</span>

        <span class="n">request_model</span> <span class="o">=</span> <span class="n">OKXPremiumIndicatorSignalRequestForm</span><span class="p">(</span>
            <span class="n">InstIdAPIKey</span><span class="o">=</span><span class="s1">&#39;place_holder_until_generated&#39;</span><span class="p">,</span>  <span class="c1"># TODO this should be a valid API key for the endpoint</span>
            <span class="n">OKXSignalInput</span><span class="o">=</span><span class="n">okx_signal</span><span class="p">,</span>
            <span class="n">PremiumIndicatorSignals</span><span class="o">=</span><span class="n">okx_premium_indicator_signals</span>
        <span class="p">)</span>

        <span class="k">if</span> <span class="n">only_return_request_model</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">request_model</span>

        <span class="n">signal_response</span> <span class="o">=</span> <span class="k">await</span> <span class="n">okx_premium_indicator_handler</span><span class="p">(</span><span class="n">indicator_input</span><span class="o">=</span><span class="n">request_model</span><span class="p">)</span>

        <span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s1">&#39;</span><span class="si">{</span><span class="n">signal_response</span><span class="si">= }</span><span class="s1">&#39;</span><span class="p">)</span>
        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">signal_response</span><span class="p">,</span> <span class="nb">dict</span><span class="p">)</span> <span class="ow">and</span> <span class="p">(</span><span class="n">signal_response</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;error&#39;</span><span class="p">)</span> <span class="ow">or</span> <span class="n">signal_response</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;red_button&#39;</span><span class="p">)):</span>
            <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;Is instance of dict&#39;</span><span class="p">)</span>
            <span class="n">output_response_card</span><span class="o">.</span><span class="n">items</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">copyable_text</span><span class="o">.</span><span class="n">value</span> <span class="o">=</span> <span class="n">okx_signal_txt_header</span> <span class="o">+</span> <span class="n">pprint</span><span class="o">.</span><span class="n">pformat</span><span class="p">(</span><span class="n">signal_response</span><span class="p">,</span>
                                                                                                       <span class="n">compact</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
                                                                                                       <span class="n">sort_dicts</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
                                                                                                       <span class="n">width</span><span class="o">=</span><span class="mi">100</span><span class="p">,</span>
                                                                                                       <span class="n">depth</span><span class="o">=</span><span class="mi">5</span><span class="p">)</span>
        <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">signal_response</span><span class="p">,</span> <span class="n">InstrumentStatusReport</span><span class="p">):</span>
            <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;Is instance of InstrumentStatusReport&#39;</span><span class="p">)</span>
            <span class="n">output_response_card</span><span class="o">.</span><span class="n">items</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">copyable_text</span><span class="o">.</span><span class="n">value</span> <span class="o">=</span> <span class="n">okx_signal_txt_header</span> <span class="o">+</span> <span class="n">pprint</span><span class="o">.</span><span class="n">pformat</span><span class="p">(</span><span class="n">signal_response</span><span class="p">,</span>
                                                                                                       <span class="n">compact</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
                                                                                                       <span class="n">sort_dicts</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
                                                                                                       <span class="n">width</span><span class="o">=</span><span class="mi">100</span><span class="p">,</span>
                                                                                                       <span class="n">depth</span><span class="o">=</span><span class="mi">5</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;Is instance of else&#39;</span><span class="p">)</span>
            <span class="n">output_response_card</span><span class="o">.</span><span class="n">items</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">copyable_text</span><span class="o">.</span><span class="n">value</span> <span class="o">=</span> <span class="n">okx_signal_txt_header</span> <span class="o">+</span> <span class="n">pprint</span><span class="o">.</span><span class="n">pformat</span><span class="p">(</span><span class="n">signal_response</span><span class="p">,</span>
                                                                                                       <span class="n">compact</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
                                                                                                       <span class="n">sort_dicts</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
                                                                                                       <span class="n">width</span><span class="o">=</span><span class="mi">100</span><span class="p">,</span>
                                                                                                       <span class="n">depth</span><span class="o">=</span><span class="mi">5</span><span class="p">)</span>
    <span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
        <span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s1">&#39;</span><span class="si">{</span><span class="n">e</span><span class="w"> </span><span class="si">= }</span><span class="s1">&#39;</span><span class="p">)</span>
        <span class="n">output_response_card</span><span class="o">.</span><span class="n">items</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">copyable_text</span><span class="o">.</span><span class="n">value</span> <span class="o">=</span> <span class="sa">f</span><span class="s2">&quot;</span><span class="si">{</span><span class="n">e</span><span class="w"> </span><span class="si">= }</span><span class="s2">&quot;</span>
        <span class="k">await</span> <span class="n">q</span><span class="o">.</span><span class="n">page</span><span class="o">.</span><span class="n">save</span><span class="p">()</span>
        <span class="k">return</span>

    <span class="k">await</span> <span class="n">q</span><span class="o">.</span><span class="n">page</span><span class="o">.</span><span class="n">save</span><span class="p">()</span></div>


<span class="c1"># premium_indicator_signal_params = {att: q.client[f&#39;okx_dashboard_page_okx_premium_indicator_{att}&#39;] for att in</span>
<span class="c1">#                                    OKX_PREMIUM_INDICATOR_SIGNAL_INPUT_KEYS}</span>
<span class="c1"># keys_to_remove = []</span>
<span class="c1"># for k, v in premium_indicator_signal_params.items():</span>
<span class="c1">#     if v == &#39;&#39; or v is None:</span>
<span class="c1">#         print(f&#39;Warning: {k} is empty&#39;)</span>
<span class="c1">#         keys_to_remove.append(k)</span>
<span class="c1"># for k in keys_to_remove:</span>
<span class="c1">#     premium_indicator_signal_params.pop(k)</span>
<span class="c1">#</span>
<span class="c1"># for k in OKX_PREMIUM_INDICATOR_SIGNAL_INPUT_KEYS:</span>
<span class="c1">#     if k not in premium_indicator_signal_params:</span>
<span class="c1">#         premium_indicator_signal_params[k] = &#39;0&#39;</span>
<span class="c1">#</span>
<span class="c1"># okx_premium_indicator = PremiumIndicatorSignals(**premium_indicator_signal_params)</span>
<span class="c1"># q.client.okx_dashboard_page_okx_signal_input = okx_premium_indicator</span>
<span class="c1">#</span>
<span class="c1"># print(f&#39;{q.client.okx_dashboard_page_okx_signal_input = }&#39;)</span>
</pre></div>

           </div>
          </div>
          <footer>

  <hr/>

  <div role="contentinfo">
    <p>&#169; Copyright 2024, Ruben Fernandez Carbon.</p>
  </div>

  Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a
    <a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a>
    provided by <a href="https://readthedocs.org">Read the Docs</a>.
   

</footer>
        </div>
      </div>
    </section>
  </div>
  <script>
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script> 

</body>
</html>